rettiwt-api 1.1.2 → 1.1.5
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 +20 -0
- package/dist/graphql/enums/Errors.js +28 -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 +4 -4
- package/dist/graphql/resolvers/UserResolver.js +23 -19
- 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/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/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 +45 -21
- package/dist/services/data/UserService.js +78 -75
- 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 +4 -4
- package/dist/services/helper/extractors/Users.js +1 -1
- 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/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/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/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/user/User.js.map +1 -1
- 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/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +64 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1280 -0
- package/docs/classes/AccountService.html +303 -0
- package/docs/classes/AuthCookie.html +146 -0
- package/docs/classes/AuthService.html +147 -0
- package/docs/classes/CacheService.html +157 -0
- package/docs/classes/Cursor.html +102 -0
- package/docs/classes/CursoredData.html +126 -0
- package/docs/classes/DataValidationError.html +119 -0
- package/docs/classes/FetcherService.html +225 -0
- package/docs/classes/Tweet.html +210 -0
- package/docs/classes/TweetEntities.html +128 -0
- package/docs/classes/TweetFilter.html +204 -0
- package/docs/classes/TweetListArgs.html +118 -0
- package/docs/classes/TweetService.html +313 -0
- package/docs/classes/User.html +230 -0
- package/docs/classes/UserListArgs.html +118 -0
- package/docs/classes/UserService.html +315 -0
- package/docs/enums/HttpMethods.html +74 -0
- package/docs/functions/Rettiwt.html +99 -0
- package/docs/index.html +161 -0
- package/docs/interfaces/IAuthCookie.html +104 -0
- package/docs/interfaces/ICursor.html +77 -0
- package/docs/interfaces/ICursoredData.html +93 -0
- package/docs/interfaces/IDataContext.html +91 -0
- package/docs/interfaces/IListArgs.html +87 -0
- package/docs/interfaces/ITweet.html +176 -0
- package/docs/interfaces/ITweetEntities.html +104 -0
- package/docs/interfaces/ITweetFilter.html +158 -0
- package/docs/interfaces/IUser.html +194 -0
- package/docs/modules.html +109 -0
- package/package.json +5 -2
- package/src/enums/Errors.ts +21 -0
- package/src/graphql/enums/Errors.ts +21 -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 +18 -20
- package/src/graphql/types/TweetTypes.ts +2 -2
- package/src/graphql/types/UserTypes.ts +1 -1
- 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 +77 -58
- package/src/services/data/UserService.ts +93 -89
- 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 +5 -5
- 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/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,17 +2,18 @@
|
|
|
2
2
|
import ResolverBase from './ResolverBase';
|
|
3
3
|
|
|
4
4
|
// TYPES
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { IDataContext } from '../../types/Rettiwt'
|
|
6
|
+
import { TweetFilter } from '../../models/args/TweetFilter';
|
|
7
|
+
import { Cursor } from '../../models/data/CursoredData';
|
|
8
|
+
import { DataErrors } from '../enums/Errors';
|
|
8
9
|
|
|
9
10
|
export default class TweetResolver extends ResolverBase {
|
|
10
11
|
// MEMBER DATA
|
|
11
12
|
private batchSize: number; // To store the batch size while fetching data
|
|
12
13
|
// MEMBER METHODS
|
|
13
|
-
constructor(context:
|
|
14
|
+
constructor(context: IDataContext) {
|
|
14
15
|
super(context);
|
|
15
|
-
this.batchSize =
|
|
16
|
+
this.batchSize = 100;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -21,7 +22,9 @@ export default class TweetResolver extends ResolverBase {
|
|
|
21
22
|
*/
|
|
22
23
|
async resolveTweet(id: string): Promise<any> {
|
|
23
24
|
// Getting the data
|
|
24
|
-
let res = await this.context.tweets.
|
|
25
|
+
let res = await this.context.tweets.getTweetDetails(id).catch(error => {
|
|
26
|
+
throw this.getGraphQLError(error);
|
|
27
|
+
});
|
|
25
28
|
|
|
26
29
|
// Evaluating response
|
|
27
30
|
return res;
|
|
@@ -37,22 +40,22 @@ export default class TweetResolver extends ResolverBase {
|
|
|
37
40
|
let tweets: any[] = []; // To store the list of tweets
|
|
38
41
|
let next: Cursor = new Cursor(cursor); // To store cursor to next batch
|
|
39
42
|
let total: number = 0; // To store the total number of tweets fetched
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
throw new Error(ValidationErrors.InvalidTweetFilter);
|
|
44
|
-
}
|
|
43
|
+
|
|
44
|
+
/** The batch size while fetching tweets is lower (=20), compared to other data related to a tweet (=100). */
|
|
45
|
+
let batchSize: number = 20; //
|
|
45
46
|
|
|
46
47
|
// If required count less than batch size, setting batch size to required count
|
|
47
|
-
|
|
48
|
+
batchSize = (count < batchSize) ? count : batchSize;
|
|
48
49
|
|
|
49
50
|
// Repeatedly fetching data as long as total data fetched is less than requried
|
|
50
51
|
do {
|
|
51
52
|
// If this is the last batch, change batch size to number of remaining tweets
|
|
52
|
-
|
|
53
|
+
batchSize = ((count - total) < batchSize) ? (count - total) : batchSize;
|
|
53
54
|
|
|
54
55
|
// Getting the data
|
|
55
|
-
const res = await this.context.tweets.getTweets(filter,
|
|
56
|
+
const res = await this.context.tweets.getTweets(filter, batchSize, next.value ).catch(error => {
|
|
57
|
+
throw this.getGraphQLError(error);
|
|
58
|
+
});
|
|
56
59
|
|
|
57
60
|
// If data is available
|
|
58
61
|
if (res.list?.length) {
|
|
@@ -109,7 +112,9 @@ export default class TweetResolver extends ResolverBase {
|
|
|
109
112
|
};
|
|
110
113
|
|
|
111
114
|
// Fetching the quotes using resolveTweets method
|
|
112
|
-
quotes = await this.resolveTweets(filter, count, cursor)
|
|
115
|
+
quotes = await this.resolveTweets(filter, count, cursor).catch(error => {
|
|
116
|
+
throw this.getGraphQLError(error);
|
|
117
|
+
});
|
|
113
118
|
|
|
114
119
|
return quotes;
|
|
115
120
|
}
|
|
@@ -139,7 +144,9 @@ export default class TweetResolver extends ResolverBase {
|
|
|
139
144
|
this.batchSize = ((count - total) < this.batchSize) ? (count - total) : this.batchSize;
|
|
140
145
|
|
|
141
146
|
// Getting the data
|
|
142
|
-
const res = await this.context.tweets.getTweetLikers(id, this.batchSize, next.value)
|
|
147
|
+
const res = await this.context.tweets.getTweetLikers(id, this.batchSize, next.value).catch(error => {
|
|
148
|
+
throw this.getGraphQLError(error);
|
|
149
|
+
});
|
|
143
150
|
|
|
144
151
|
// If data is available
|
|
145
152
|
if (res.list?.length) {
|
|
@@ -194,7 +201,9 @@ export default class TweetResolver extends ResolverBase {
|
|
|
194
201
|
this.batchSize = ((count - total) < this.batchSize) ? (count - total) : this.batchSize;
|
|
195
202
|
|
|
196
203
|
// Getting the data
|
|
197
|
-
const res = await this.context.tweets.getTweetRetweeters(id, this.batchSize, next.value)
|
|
204
|
+
const res = await this.context.tweets.getTweetRetweeters(id, this.batchSize, next.value).catch(error => {
|
|
205
|
+
throw this.getGraphQLError(error);
|
|
206
|
+
});
|
|
198
207
|
|
|
199
208
|
// If data is available
|
|
200
209
|
if (res.list?.length) {
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
import ResolverBase from './ResolverBase';
|
|
3
3
|
|
|
4
4
|
// TYPES
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { IDataContext } from '../../types/Rettiwt'
|
|
6
|
+
import { Cursor } from '../../models/data/CursoredData';
|
|
7
|
+
import { DataErrors } from '../enums/Errors';
|
|
7
8
|
|
|
8
9
|
export default class UserResolver extends ResolverBase {
|
|
9
10
|
// MEMBER DATA
|
|
10
11
|
private batchSize: number; // To store the batch size when fetching data
|
|
11
12
|
|
|
12
13
|
// MEMBER METHODS
|
|
13
|
-
constructor(context:
|
|
14
|
+
constructor(context: IDataContext) {
|
|
14
15
|
super(context);
|
|
15
16
|
this.batchSize = 40;
|
|
16
17
|
}
|
|
@@ -18,21 +19,12 @@ export default class UserResolver extends ResolverBase {
|
|
|
18
19
|
/**
|
|
19
20
|
* @returns The details of the target twitter user
|
|
20
21
|
* @param userName The user name of the target twitter user
|
|
21
|
-
* @param id The id of the target twitter user
|
|
22
|
+
* @param id The id/username of the target twitter user
|
|
22
23
|
*/
|
|
23
|
-
async resolveUserDetails(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
// If id is supplied
|
|
29
|
-
else if (id) {
|
|
30
|
-
return await this.context.users.getUserDetailsById(id);
|
|
31
|
-
}
|
|
32
|
-
// If neither userName nor id is supplied
|
|
33
|
-
else {
|
|
34
|
-
throw new Error(ValidationErrors.NoUserIdentification);
|
|
35
|
-
}
|
|
24
|
+
async resolveUserDetails(id: string): Promise<any> {
|
|
25
|
+
return await this.context.users.getUserDetails(id).catch(error => {
|
|
26
|
+
throw this.getGraphQLError(error);
|
|
27
|
+
});
|
|
36
28
|
}
|
|
37
29
|
|
|
38
30
|
/**
|
|
@@ -60,7 +52,9 @@ export default class UserResolver extends ResolverBase {
|
|
|
60
52
|
this.batchSize = ((count - total) < this.batchSize) ? (count - total) : this.batchSize;
|
|
61
53
|
|
|
62
54
|
// Getting the data
|
|
63
|
-
const res = await this.context.users.getUserLikes(id, this.batchSize, next.value)
|
|
55
|
+
const res = await this.context.users.getUserLikes(id, this.batchSize, next.value).catch(error => {
|
|
56
|
+
throw this.getGraphQLError(error);
|
|
57
|
+
});
|
|
64
58
|
|
|
65
59
|
// If data is available
|
|
66
60
|
if (res.list?.length) {
|
|
@@ -115,7 +109,9 @@ export default class UserResolver extends ResolverBase {
|
|
|
115
109
|
this.batchSize = ((count - total) < this.batchSize) ? (count - total) : this.batchSize;
|
|
116
110
|
|
|
117
111
|
// Getting the data
|
|
118
|
-
const res = await this.context.users.getUserFollowers(id, this.batchSize, next.value)
|
|
112
|
+
const res = await this.context.users.getUserFollowers(id, this.batchSize, next.value).catch(error => {
|
|
113
|
+
throw this.getGraphQLError(error);
|
|
114
|
+
});
|
|
119
115
|
|
|
120
116
|
// If data is available
|
|
121
117
|
if (res.list?.length) {
|
|
@@ -170,7 +166,9 @@ export default class UserResolver extends ResolverBase {
|
|
|
170
166
|
this.batchSize = ((count - total) < this.batchSize) ? (count - total) : this.batchSize;
|
|
171
167
|
|
|
172
168
|
// Getting the data
|
|
173
|
-
const res = await this.context.users.getUserFollowing(id, this.batchSize, next.value)
|
|
169
|
+
const res = await this.context.users.getUserFollowing(id, this.batchSize, next.value).catch(error => {
|
|
170
|
+
throw this.getGraphQLError(error);
|
|
171
|
+
});
|
|
174
172
|
|
|
175
173
|
// If data is available
|
|
176
174
|
if (res.list?.length) {
|
|
@@ -17,7 +17,7 @@ export const TweetTokens: GraphQLObjectType = new GraphQLObjectType({
|
|
|
17
17
|
urls: { type: new GraphQLList(GraphQLString) },
|
|
18
18
|
mentionedUsers: {
|
|
19
19
|
type: UserList,
|
|
20
|
-
resolve: (parent, args, context) => parent.mentionedUsers.map((user: string) => new UserResolver(context).resolveUserDetails(
|
|
20
|
+
resolve: (parent, args, context) => parent.mentionedUsers.map((user: string) => new UserResolver(context).resolveUserDetails(user))
|
|
21
21
|
},
|
|
22
22
|
media: { type: new GraphQLList(GraphQLString) },
|
|
23
23
|
})
|
|
@@ -30,7 +30,7 @@ export const Tweet: GraphQLObjectType = new GraphQLObjectType({
|
|
|
30
30
|
id: { type: GraphQLString },
|
|
31
31
|
tweetBy: {
|
|
32
32
|
type: User,
|
|
33
|
-
resolve: (parent, args, context) => new UserResolver(context).resolveUserDetails(
|
|
33
|
+
resolve: (parent, args, context) => new UserResolver(context).resolveUserDetails(parent.tweetBy)
|
|
34
34
|
},
|
|
35
35
|
createdAt: { type: GraphQLString },
|
|
36
36
|
entities: { type: TweetTokens },
|
|
@@ -4,7 +4,7 @@ import { GraphQLBoolean, GraphQLObjectType, GraphQLString, GraphQLInt, GraphQLLi
|
|
|
4
4
|
// TYPES
|
|
5
5
|
import { Tweet, TweetList } from './TweetTypes'
|
|
6
6
|
import { Cursor } from './Global';
|
|
7
|
-
import { TweetFilter } from '../../
|
|
7
|
+
import { TweetFilter } from '../../models/args/TweetFilter';
|
|
8
8
|
|
|
9
9
|
// RESOLVERS
|
|
10
10
|
import UserResolver from '../resolvers/UserResolver';
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
+
// PACKAGES
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
|
|
1
4
|
// SERVICES
|
|
2
|
-
import { AuthService } from "./services/AuthService";
|
|
5
|
+
import { AuthService } from "./services/auth/AuthService";
|
|
3
6
|
import { UserService } from "./services/data/UserService";
|
|
4
7
|
import { TweetService } from "./services/data/TweetService";
|
|
5
|
-
import { AccountService } from "./services/
|
|
8
|
+
import { AccountService } from "./services/auth/AccountService";
|
|
9
|
+
|
|
10
|
+
// TYPES
|
|
11
|
+
import { IAuthCookie } from './types/Authentication';
|
|
6
12
|
|
|
7
13
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
14
|
+
* The instance for fetching data from Twitter.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*
|
|
18
|
+
* @param cookie The cookie to use to fetch data.
|
|
19
|
+
*
|
|
20
|
+
* @returns The API for fetching user and tweet data.
|
|
21
|
+
*
|
|
10
22
|
* @remarks The cookie can be obtained by using {@link AccountService.login} method.
|
|
11
|
-
* To use the {@link AccountService.login} method, create a {@link Rettiwt} instance without passing any cookie
|
|
23
|
+
* To use the {@link AccountService.login} method, create a {@link Rettiwt} instance without passing any cookie .
|
|
12
24
|
* Then use the {@link AccountService.login} method of {@link AccountService} to get the cookie.
|
|
13
25
|
*/
|
|
14
|
-
export const Rettiwt = (cookie
|
|
15
|
-
// Creating new auth service instance using the given cookie
|
|
26
|
+
export const Rettiwt = (cookie?: IAuthCookie) => {
|
|
27
|
+
// Creating new auth service instance using the given cookie
|
|
16
28
|
const auth: AuthService = new AuthService(cookie);
|
|
17
29
|
|
|
18
30
|
// Using the auth service instance to create data services instances
|
|
@@ -24,17 +36,27 @@ export const Rettiwt = (cookie: string = '') => {
|
|
|
24
36
|
}
|
|
25
37
|
|
|
26
38
|
// Exporting classes
|
|
27
|
-
export * from './services/AuthService';
|
|
28
|
-
export * from './services/
|
|
29
|
-
export * from './services/FetcherService';
|
|
30
|
-
export * from './services/accounts/AccountService';
|
|
39
|
+
export * from './services/auth/AuthService';
|
|
40
|
+
export * from './services/auth/AccountService';
|
|
31
41
|
export * from './services/data/TweetService';
|
|
32
42
|
export * from './services/data/UserService';
|
|
43
|
+
export * from './services/util/CacheService';
|
|
44
|
+
export * from './services/util/FetcherService';
|
|
33
45
|
|
|
34
46
|
// Exporting types
|
|
35
|
-
export * from './types/
|
|
36
|
-
export
|
|
37
|
-
export * from './types/
|
|
38
|
-
export * from './types/
|
|
39
|
-
export * from './types/
|
|
40
|
-
export * from './types/
|
|
47
|
+
export * from './types/Args';
|
|
48
|
+
export { IAuthCookie } from './types/Authentication';
|
|
49
|
+
export * from './types/Rettiwt';
|
|
50
|
+
export * from './types/Service';
|
|
51
|
+
export * from './types/Tweet';
|
|
52
|
+
export * from './types/User';
|
|
53
|
+
|
|
54
|
+
// Exporting models
|
|
55
|
+
export * from './models/args/TweetFilter';
|
|
56
|
+
export * from './models/args/TweetListArgs';
|
|
57
|
+
export * from './models/args/UserListArgs';
|
|
58
|
+
export * from './models/auth/AuthCookie';
|
|
59
|
+
export * from './models/data/CursoredData';
|
|
60
|
+
export * from './models/data/Tweet';
|
|
61
|
+
export * from './models/data/User';
|
|
62
|
+
export * from './models/errors/DataValidationError';
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// PACKAGE
|
|
2
|
+
import { IsArray, IsBoolean, IsNumberString, IsString, IsOptional, IsDateString, validateSync } from 'class-validator';
|
|
3
|
+
|
|
4
|
+
// TYPES
|
|
5
|
+
import { ITweetFilter } from '../../types/Args';
|
|
6
|
+
import { DataValidationError } from '../errors/DataValidationError';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The filter to be used for fetching tweets from Twitter.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export class TweetFilter implements ITweetFilter {
|
|
14
|
+
/** The list of words to search. */
|
|
15
|
+
@IsArray()
|
|
16
|
+
@IsString({ each: true })
|
|
17
|
+
@IsOptional()
|
|
18
|
+
words?: string[];
|
|
19
|
+
|
|
20
|
+
/** The list of hashtags to search.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* '#' must be excluded from the hashtag!
|
|
24
|
+
*/
|
|
25
|
+
@IsArray()
|
|
26
|
+
@IsString({ each: true })
|
|
27
|
+
@IsOptional()
|
|
28
|
+
hashtags?: string[];
|
|
29
|
+
|
|
30
|
+
/** The list of usernames whose tweets are to be searched.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* '@' must be excluded from the username!
|
|
34
|
+
*/
|
|
35
|
+
@IsArray()
|
|
36
|
+
@IsString({ each: true })
|
|
37
|
+
@IsOptional()
|
|
38
|
+
fromUsers?: string[];
|
|
39
|
+
|
|
40
|
+
/** The list of username to whom the tweets to be searched, are adressed.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* '@' must be excluded from the username!
|
|
44
|
+
*/
|
|
45
|
+
@IsArray()
|
|
46
|
+
@IsString({ each: true })
|
|
47
|
+
@IsOptional()
|
|
48
|
+
toUsers?: string[];
|
|
49
|
+
|
|
50
|
+
/** The list of username mentioned in the tweets to search.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* '@' must be excluded from the username!
|
|
54
|
+
*/
|
|
55
|
+
@IsArray()
|
|
56
|
+
@IsString({ each: true })
|
|
57
|
+
@IsOptional()
|
|
58
|
+
mentions?: string[];
|
|
59
|
+
|
|
60
|
+
/** The date starting from which tweets are to be searched.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* Must be in the format YYYY-MM-DD.
|
|
64
|
+
*/
|
|
65
|
+
@IsOptional()
|
|
66
|
+
@IsDateString()
|
|
67
|
+
startDate?: string;
|
|
68
|
+
|
|
69
|
+
/** The date upto which tweets are to be searched.
|
|
70
|
+
*
|
|
71
|
+
* @remarks
|
|
72
|
+
* Must be in the format YYYY-MM-DD.
|
|
73
|
+
*/
|
|
74
|
+
@IsOptional()
|
|
75
|
+
@IsDateString()
|
|
76
|
+
endDate?: string;
|
|
77
|
+
|
|
78
|
+
/** The id of the tweet, after which the tweets are to be searched. */
|
|
79
|
+
@IsNumberString()
|
|
80
|
+
@IsOptional()
|
|
81
|
+
sinceId?: string;
|
|
82
|
+
|
|
83
|
+
/** The id of the tweet which is quoted in the tweets to search. */
|
|
84
|
+
@IsNumberString()
|
|
85
|
+
@IsOptional()
|
|
86
|
+
quoted?: string;
|
|
87
|
+
|
|
88
|
+
/** Whether to fetch tweets that are links or not.
|
|
89
|
+
*
|
|
90
|
+
* @defaultValue false
|
|
91
|
+
*/
|
|
92
|
+
@IsBoolean()
|
|
93
|
+
@IsOptional()
|
|
94
|
+
links?: boolean;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param filter The incoming filter in JSON format.
|
|
98
|
+
*/
|
|
99
|
+
constructor(filter: TweetFilter) {
|
|
100
|
+
this.endDate = filter.endDate;
|
|
101
|
+
this.fromUsers = filter.fromUsers;
|
|
102
|
+
this.hashtags = filter.hashtags;
|
|
103
|
+
this.links = filter.links;
|
|
104
|
+
this.mentions = filter.mentions;
|
|
105
|
+
this.quoted = filter.quoted;
|
|
106
|
+
this.sinceId = filter.sinceId;
|
|
107
|
+
this.startDate = filter.startDate;
|
|
108
|
+
this.toUsers = filter.toUsers;
|
|
109
|
+
this.words = filter.words;
|
|
110
|
+
|
|
111
|
+
// Validating the filter
|
|
112
|
+
const validationResult = validateSync(this);
|
|
113
|
+
|
|
114
|
+
// If valiation error occured
|
|
115
|
+
if (validationResult.length) {
|
|
116
|
+
throw new DataValidationError(validationResult);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// PACKAGES
|
|
2
|
+
import { IsInt, IsString, IsOptional, Min, validateSync, Max, ValidateIf } from 'class-validator';
|
|
3
|
+
|
|
4
|
+
// TYPES
|
|
5
|
+
import { IListArgs } from '../../types/Args';
|
|
6
|
+
import { DataValidationError } from '../errors/DataValidationError';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The arguments for fetching cursored list in TweetService.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export class TweetListArgs implements IListArgs {
|
|
14
|
+
/** The number of data items to fetch.
|
|
15
|
+
*
|
|
16
|
+
* @defaultValue 10
|
|
17
|
+
* @remarks Must be >= 10 and <= 100
|
|
18
|
+
*/
|
|
19
|
+
@IsInt()
|
|
20
|
+
@IsOptional()
|
|
21
|
+
@Max(100)
|
|
22
|
+
@ValidateIf(ob => ob.cursor.length == 0)
|
|
23
|
+
@Min(10)
|
|
24
|
+
count: number;
|
|
25
|
+
|
|
26
|
+
/** The cursor to the batch of data to fetch. */
|
|
27
|
+
@IsString()
|
|
28
|
+
@IsOptional()
|
|
29
|
+
cursor: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param count The number of data items to fetch.
|
|
33
|
+
* @param cursor The cursor to the batch of data to fetch.
|
|
34
|
+
*/
|
|
35
|
+
constructor(count: number = 10, cursor: string = '') {
|
|
36
|
+
this.count = count;
|
|
37
|
+
this.cursor = cursor;
|
|
38
|
+
|
|
39
|
+
// Validating the arguments
|
|
40
|
+
const validationResult = validateSync(this);
|
|
41
|
+
|
|
42
|
+
// If valiation error occured
|
|
43
|
+
if (validationResult.length) {
|
|
44
|
+
throw new DataValidationError(validationResult);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// PACKAGES
|
|
2
|
+
import { IsInt, IsString, IsOptional, Min, validateSync, Max, ValidateIf } from 'class-validator';
|
|
3
|
+
|
|
4
|
+
// TYPES
|
|
5
|
+
import { IListArgs } from '../../types/Args';
|
|
6
|
+
import { DataValidationError } from '../errors/DataValidationError';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The arguments for fetching cursored list in TweetService.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export class UserListArgs implements IListArgs {
|
|
14
|
+
/** The number of data items to fetch.
|
|
15
|
+
*
|
|
16
|
+
* @defaultValue 40
|
|
17
|
+
* @remarks Must be >= 40 and <= 100
|
|
18
|
+
*/
|
|
19
|
+
@IsInt()
|
|
20
|
+
@IsOptional()
|
|
21
|
+
@Max(100)
|
|
22
|
+
@ValidateIf(ob => ob.cursor.length == 0)
|
|
23
|
+
@Min(40)
|
|
24
|
+
count: number;
|
|
25
|
+
|
|
26
|
+
/** The cursor to the batch of data to fetch. */
|
|
27
|
+
@IsString()
|
|
28
|
+
@IsOptional()
|
|
29
|
+
cursor: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param count The number of data items to fetch.
|
|
33
|
+
* @param cursor The cursor to the batch of data to fetch.
|
|
34
|
+
*/
|
|
35
|
+
constructor(count: number = 40, cursor: string = '') {
|
|
36
|
+
this.count = count;
|
|
37
|
+
this.cursor = cursor;
|
|
38
|
+
|
|
39
|
+
// Validating the arguments
|
|
40
|
+
const validationResult = validateSync(this);
|
|
41
|
+
|
|
42
|
+
// If valiation error occured
|
|
43
|
+
if (validationResult.length) {
|
|
44
|
+
throw new DataValidationError(validationResult);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// TYPES
|
|
2
|
+
import { IAuthCookie } from '../../types/Authentication';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The cookie containing the tokens that are used to authenticate against Twitter.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export class AuthCookie implements IAuthCookie {
|
|
10
|
+
/** Token used to authenticate a device. */
|
|
11
|
+
kdt: string;
|
|
12
|
+
|
|
13
|
+
/** Token used to authenticate a user using a Twitter ID. */
|
|
14
|
+
twid: string;
|
|
15
|
+
|
|
16
|
+
/** The CSRF token of the session. */
|
|
17
|
+
ct0: string;
|
|
18
|
+
|
|
19
|
+
/** The authentication token used while logging in to the account. */
|
|
20
|
+
auth_token: string;
|
|
21
|
+
|
|
22
|
+
constructor(cookie?: IAuthCookie) {
|
|
23
|
+
this.auth_token = cookie?.auth_token ?? '';
|
|
24
|
+
this.ct0 = cookie?.ct0 ?? '';
|
|
25
|
+
this.kdt = cookie?.kdt ?? '';
|
|
26
|
+
this.twid = cookie?.twid ?? '';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @returns The string respresentation of this cookie in the valid cookie string format.
|
|
31
|
+
*/
|
|
32
|
+
toString(): string {
|
|
33
|
+
/** The string representation of this cookie. */
|
|
34
|
+
let cookieString: string = '';
|
|
35
|
+
|
|
36
|
+
// Iterating through the (key, value) pairs of this cookie
|
|
37
|
+
for (let [key, value] of Object.entries(this)) {
|
|
38
|
+
cookieString += `${key}=${value};`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return cookieString;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// TYPES
|
|
2
|
+
import { ICursor,ICursoredData } from "../../types/Service";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The cursor to the batch of data to be fetched.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export class Cursor implements ICursor {
|
|
10
|
+
/** The cursor string. */
|
|
11
|
+
value: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initializes a new cursor from the given cursor string.
|
|
15
|
+
*
|
|
16
|
+
* @param cursorStr The string representation of the cursor.
|
|
17
|
+
*/
|
|
18
|
+
constructor(cursorStr: string) {
|
|
19
|
+
this.value = cursorStr;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The data that us fetched batch-wise along with a cursor.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*
|
|
28
|
+
* @typeParam Type - The type of data present in the list.
|
|
29
|
+
*/
|
|
30
|
+
export class CursoredData<T> implements ICursoredData<T> {
|
|
31
|
+
/** The list of data of the given type. */
|
|
32
|
+
list: T[];
|
|
33
|
+
|
|
34
|
+
/** The cursor to the next batch of data. */
|
|
35
|
+
next: Cursor;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param list The list of data item to store.
|
|
39
|
+
* @param next The cursor to the next batch of data.
|
|
40
|
+
*/
|
|
41
|
+
constructor(list: T[] = [], next: string = '') {
|
|
42
|
+
this.list = list;
|
|
43
|
+
this.next = new Cursor(next);
|
|
44
|
+
}
|
|
45
|
+
}
|