rettiwt-api 1.0.5 → 1.0.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 +2 -2
- package/dist/{queries → graphql/queries}/RootQuery.d.ts +0 -0
- package/dist/{queries → graphql/queries}/RootQuery.js +15 -3
- package/dist/graphql/queries/RootQuery.js.map +1 -0
- package/dist/graphql/resolvers/AccountResolver.d.ts +12 -0
- package/dist/graphql/resolvers/AccountResolver.js +84 -0
- package/dist/graphql/resolvers/AccountResolver.js.map +1 -0
- package/dist/{resolvers → graphql/resolvers}/ResolverBase.d.ts +1 -1
- package/dist/{resolvers → graphql/resolvers}/ResolverBase.js +0 -0
- package/dist/graphql/resolvers/ResolverBase.js.map +1 -0
- package/dist/{resolvers → graphql/resolvers}/TweetResolver.d.ts +10 -9
- package/dist/{resolvers → graphql/resolvers}/TweetResolver.js +51 -35
- package/dist/graphql/resolvers/TweetResolver.js.map +1 -0
- package/dist/{resolvers → graphql/resolvers}/UserResolver.d.ts +5 -4
- package/dist/{resolvers → graphql/resolvers}/UserResolver.js +51 -35
- package/dist/graphql/resolvers/UserResolver.js.map +1 -0
- package/dist/{models/graphql → graphql/types}/Global.d.ts +0 -0
- package/dist/{models/graphql → graphql/types}/Global.js +0 -0
- package/dist/graphql/types/Global.js.map +1 -0
- package/dist/graphql/types/TweetTypes.d.ts +4 -0
- package/dist/{models/graphql → graphql/types}/TweetTypes.js +5 -7
- package/dist/graphql/types/TweetTypes.js.map +1 -0
- package/dist/graphql/types/UserTypes.d.ts +3 -0
- package/dist/{models/graphql → graphql/types}/UserTypes.js +9 -11
- package/dist/graphql/types/UserTypes.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/server.js +6 -4
- package/dist/server.js.map +1 -1
- package/dist/services/AuthService.js +2 -2
- package/dist/services/AuthService.js.map +1 -1
- package/dist/services/CacheService.d.ts +3 -3
- package/dist/services/CacheService.js +22 -75
- package/dist/services/CacheService.js.map +1 -1
- package/dist/services/FetcherService.d.ts +14 -4
- package/dist/services/FetcherService.js +58 -52
- package/dist/services/FetcherService.js.map +1 -1
- package/dist/services/accounts/AccountService.d.ts +42 -0
- package/dist/services/accounts/AccountService.js +291 -0
- package/dist/services/accounts/AccountService.js.map +1 -0
- package/dist/services/accounts/LoginFlows.d.ts +77 -0
- package/dist/services/accounts/LoginFlows.js +92 -0
- package/dist/services/accounts/LoginFlows.js.map +1 -0
- package/dist/services/data/TweetService.d.ts +6 -6
- package/dist/services/data/TweetService.js +44 -27
- package/dist/services/data/TweetService.js.map +1 -1
- package/dist/services/data/UserAccountService.d.ts +3 -3
- package/dist/services/data/UserAccountService.js +22 -8
- package/dist/services/data/UserAccountService.js.map +1 -1
- package/dist/services/data/UserService.d.ts +42 -0
- package/dist/services/data/UserService.js +255 -0
- package/dist/services/data/UserService.js.map +1 -0
- package/dist/services/helper/Extractors.js +1 -1
- package/dist/services/helper/Extractors.js.map +1 -1
- package/dist/services/helper/Headers.d.ts +11 -1
- package/dist/services/helper/Headers.js +28 -2
- package/dist/services/helper/Headers.js.map +1 -1
- package/dist/services/helper/Parser.d.ts +1 -1
- package/dist/services/helper/Parser.js +4 -3
- package/dist/services/helper/Parser.js.map +1 -1
- package/dist/services/helper/Urls.d.ts +2 -2
- package/dist/services/helper/Urls.js +19 -3
- package/dist/services/helper/Urls.js.map +1 -1
- package/dist/services/helper/deserializers/Tweets.d.ts +12 -0
- package/dist/services/helper/deserializers/Tweets.js +92 -0
- package/dist/services/helper/deserializers/Tweets.js.map +1 -0
- package/dist/services/helper/deserializers/User.d.ts +0 -0
- package/dist/services/helper/deserializers/User.js +2 -0
- package/dist/services/helper/deserializers/User.js.map +1 -0
- package/dist/services/helper/deserializers/Users.d.ts +7 -0
- package/dist/services/helper/deserializers/Users.js +27 -0
- package/dist/services/helper/deserializers/Users.js.map +1 -0
- package/dist/services/helper/extractors/TweetExtractors.d.ts +0 -0
- package/dist/services/helper/extractors/TweetExtractors.js +2 -0
- package/dist/services/helper/extractors/TweetExtractors.js.map +1 -0
- package/dist/services/helper/extractors/Tweets.d.ts +32 -0
- package/dist/services/helper/extractors/Tweets.js +264 -0
- package/dist/services/helper/extractors/Tweets.js.map +1 -0
- package/dist/services/helper/extractors/UserExtractors.d.ts +45 -0
- package/dist/services/helper/extractors/UserExtractors.js +176 -0
- package/dist/services/helper/extractors/UserExtractors.js.map +1 -0
- package/dist/services/helper/extractors/Users.d.ts +20 -0
- package/dist/services/helper/extractors/Users.js +151 -0
- package/dist/services/helper/extractors/Users.js.map +1 -0
- package/dist/services/helper/urls/Authentication.d.ts +4 -0
- package/dist/services/helper/urls/Authentication.js +11 -0
- package/dist/services/helper/urls/Authentication.js.map +1 -0
- package/dist/services/helper/urls/Tweets.d.ts +32 -0
- package/dist/services/helper/urls/Tweets.js +51 -0
- package/dist/services/helper/urls/Tweets.js.map +1 -0
- package/dist/services/helper/urls/Urls.d.ts +4 -0
- package/dist/services/helper/urls/Urls.js +11 -0
- package/dist/services/helper/urls/Urls.js.map +1 -0
- package/dist/services/helper/urls/Users.d.ts +31 -0
- package/dist/services/helper/urls/Users.js +66 -0
- package/dist/services/helper/urls/Users.js.map +1 -0
- package/dist/types/{graphql/Errors.d.ts → Errors.d.ts} +0 -0
- package/dist/types/{graphql/Errors.js → Errors.js} +0 -0
- package/dist/types/Errors.js.map +1 -0
- package/dist/types/HTTP.d.ts +0 -7
- package/dist/types/HTTP.js +1 -10
- package/dist/types/HTTP.js.map +1 -1
- package/dist/types/Resolvers.d.ts +9 -0
- package/dist/types/Resolvers.js +3 -0
- package/dist/types/Resolvers.js.map +1 -0
- package/dist/types/Service.d.ts +2 -0
- package/dist/types/Service.js.map +1 -1
- package/dist/types/Tweet.d.ts +1 -0
- package/dist/types/Tweet.js.map +1 -1
- package/dist/types/User.d.ts +19 -0
- package/dist/types/User.js +4 -0
- package/dist/types/User.js.map +1 -0
- package/dist/types/data/Errors.d.ts +26 -0
- package/dist/types/data/Errors.js +36 -0
- package/dist/types/data/Errors.js.map +1 -0
- package/dist/types/data/Service.d.ts +29 -0
- package/dist/types/data/Service.js +19 -0
- package/dist/types/data/Service.js.map +1 -0
- package/dist/types/data/Tweet.d.ts +41 -0
- package/dist/types/data/Tweet.js +5 -0
- package/dist/types/data/Tweet.js.map +1 -0
- package/dist/types/data/User.d.ts +19 -0
- package/dist/types/data/User.js +4 -0
- package/dist/types/data/User.js.map +1 -0
- package/dist/types/raw/http/Error.d.ts +34 -0
- package/dist/types/raw/{user/Users.js → http/Error.js} +1 -1
- package/dist/types/raw/http/Error.js.map +1 -0
- package/dist/types/raw/http/Response.d.ts +34 -0
- package/dist/types/raw/http/Response.js +3 -0
- package/dist/types/raw/http/Response.js.map +1 -0
- package/package.json +4 -2
- package/src/{queries → graphql/queries}/RootQuery.ts +16 -4
- package/src/graphql/resolvers/AccountResolver.ts +22 -0
- package/src/{resolvers → graphql/resolvers}/ResolverBase.ts +1 -1
- package/src/{resolvers → graphql/resolvers}/TweetResolver.ts +43 -30
- package/src/{resolvers → graphql/resolvers}/UserResolver.ts +41 -27
- package/src/{models/graphql → graphql/types}/Global.ts +0 -0
- package/src/{models/graphql → graphql/types}/TweetTypes.ts +9 -11
- package/src/{models/graphql → graphql/types}/UserTypes.ts +13 -15
- package/src/index.ts +5 -3
- package/src/server.ts +6 -4
- package/src/services/AuthService.ts +1 -1
- package/src/services/CacheService.ts +6 -8
- package/src/services/FetcherService.ts +37 -22
- package/src/services/accounts/AccountService.ts +156 -0
- package/src/services/accounts/LoginFlows.ts +90 -0
- package/src/services/data/TweetService.ts +53 -37
- package/src/services/data/UserService.ts +187 -0
- package/src/services/helper/Headers.ts +27 -1
- package/src/services/helper/Parser.ts +6 -4
- package/src/services/helper/{Deserializers.ts → deserializers/Tweets.ts} +3 -28
- package/src/services/helper/deserializers/Users.ts +26 -0
- package/src/services/helper/extractors/Tweets.ts +252 -0
- package/src/services/helper/extractors/Users.ts +137 -0
- package/src/services/helper/urls/Authentication.ts +6 -0
- package/src/services/helper/urls/Tweets.ts +46 -0
- package/src/services/helper/urls/Users.ts +62 -0
- package/src/types/HTTP.ts +0 -8
- package/src/types/Resolvers.ts +9 -0
- package/src/types/data/Errors.ts +28 -0
- package/src/types/{Service.ts → data/Service.ts} +6 -5
- package/src/types/{Tweet.ts → data/Tweet.ts} +1 -0
- package/src/types/{UserAccount.ts → data/User.ts} +0 -0
- package/tsconfig.json +2 -2
- package/dist/models/graphql/Global.js.map +0 -1
- package/dist/models/graphql/TweetTypes.d.ts +0 -6
- package/dist/models/graphql/TweetTypes.js.map +0 -1
- package/dist/models/graphql/UserTypes.d.ts +0 -3
- package/dist/models/graphql/UserTypes.js.map +0 -1
- package/dist/queries/RootQuery.js.map +0 -1
- package/dist/resolvers/ResolverBase.js.map +0 -1
- package/dist/resolvers/TweetResolver.js.map +0 -1
- package/dist/resolvers/UserResolver.js.map +0 -1
- package/dist/test/Test.js +0 -2
- package/dist/test/Test.js.map +0 -1
- package/dist/types/graphql/Errors.js.map +0 -1
- package/dist/types/raw/user/Users.d.ts +0 -120
- package/dist/types/raw/user/Users.js.map +0 -1
- package/src/services/data/UserAccountService.ts +0 -176
- package/src/services/helper/Extractors.ts +0 -455
- package/src/services/helper/Urls.ts +0 -109
- package/src/types/graphql/Errors.ts +0 -16
- package/src/types/raw/user/Tweets.ts +0 -2847
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
// SERVICES
|
|
2
|
-
import { FetcherService } from '../FetcherService';
|
|
3
|
-
import { AuthService } from '../AuthService';
|
|
4
|
-
|
|
5
|
-
// TYPES
|
|
6
|
-
import { User } from '../../types/UserAccount';
|
|
7
|
-
import { Tweet } from '../../types/Tweet';
|
|
8
|
-
import { CursoredData } from '../../types/Service';
|
|
9
|
-
import RawUser from '../../types/raw/user/User';
|
|
10
|
-
import RawUserFollowers from '../../types/raw/user/Followers';
|
|
11
|
-
import RawUserFollowing from '../../types/raw/user/Following';
|
|
12
|
-
import RawUserLikes from '../../types/raw/user/Likes';
|
|
13
|
-
|
|
14
|
-
// URLS
|
|
15
|
-
import * as Urls from '../helper/Urls';
|
|
16
|
-
|
|
17
|
-
// EXTRACTORS
|
|
18
|
-
import * as Extractors from '../helper/Extractors';
|
|
19
|
-
|
|
20
|
-
// DESERIALIZERS
|
|
21
|
-
import * as Deserializers from '../helper/Deserializers';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* A service that deals with fetching of data related to user account
|
|
25
|
-
*/
|
|
26
|
-
export class UserAccountService extends FetcherService {
|
|
27
|
-
// MEMBER METHODS
|
|
28
|
-
constructor(auth: AuthService) {
|
|
29
|
-
super(auth);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @returns The user account details of the given user
|
|
34
|
-
* @param screenName The screen name of the target user.
|
|
35
|
-
*/
|
|
36
|
-
async getUserAccountDetails(screenName: string): Promise<User> {
|
|
37
|
-
// Fetching the raw data
|
|
38
|
-
let res: RawUser = await this.request<RawUser>(Urls.userAccountUrl(screenName), false).then(res => res.data);
|
|
39
|
-
|
|
40
|
-
// Extracting data
|
|
41
|
-
let data = Extractors.extractUserAccountDetails(res);
|
|
42
|
-
|
|
43
|
-
// Caching data
|
|
44
|
-
this.cacheData(data);
|
|
45
|
-
|
|
46
|
-
// Parsing data
|
|
47
|
-
let user = Deserializers.toUser(data.required[0]);
|
|
48
|
-
|
|
49
|
-
return user;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @returns The user account details of the user with given rest id
|
|
54
|
-
* @param restId The screen name of the target user.
|
|
55
|
-
*/
|
|
56
|
-
async getUserAccountDetailsById(restId: string): Promise<User> {
|
|
57
|
-
// Getting data from cache
|
|
58
|
-
let cachedData = await this.readData(restId);
|
|
59
|
-
|
|
60
|
-
// If data exists in cache
|
|
61
|
-
if(cachedData) {
|
|
62
|
-
return cachedData;
|
|
63
|
-
}
|
|
64
|
-
// If data does not exist in cache
|
|
65
|
-
else {
|
|
66
|
-
// Fetchin the raw data
|
|
67
|
-
let res = await this.request<RawUser>(Urls.userAccountByIdUrl(restId), false).then(res => res.data);
|
|
68
|
-
|
|
69
|
-
// Extracting data
|
|
70
|
-
let data = Extractors.extractUserAccountDetails(res);
|
|
71
|
-
|
|
72
|
-
// Caching data
|
|
73
|
-
this.cacheData(data);
|
|
74
|
-
|
|
75
|
-
// Parsing data
|
|
76
|
-
let user = Deserializers.toUser(data.required[0]);
|
|
77
|
-
|
|
78
|
-
return user;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* @returns The list of users followed by the target user
|
|
84
|
-
* @param userId The rest id of the target user
|
|
85
|
-
* @param count The batch size of the list
|
|
86
|
-
* @param cursor The cursor to next batch. If blank, first batch is fetched
|
|
87
|
-
*/
|
|
88
|
-
async getUserFollowing(userId: string, count: number, cursor: string): Promise<CursoredData<User>> {
|
|
89
|
-
// If user is not authenticated, abort
|
|
90
|
-
if(!this.isAuthenticated) {
|
|
91
|
-
return { error: new Error('Cannot fetch user following without authentication!') };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Fetchin the raw data
|
|
95
|
-
let res = await this.request<RawUserFollowing>(Urls.userFollowingUrl(userId, count, cursor)).then(res => res.data);
|
|
96
|
-
|
|
97
|
-
// Extracting data
|
|
98
|
-
let data = Extractors.extractUserFollow(res);
|
|
99
|
-
|
|
100
|
-
// Caching data
|
|
101
|
-
this.cacheData(data);
|
|
102
|
-
|
|
103
|
-
// Parsing data
|
|
104
|
-
let users = data.required.map(item => Deserializers.toUser(item));
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
list: users,
|
|
108
|
-
next: { value: data.cursor }
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @returns The list of users following the target user
|
|
114
|
-
* @param userId The rest id of the target user
|
|
115
|
-
* @param count The batch size of the list
|
|
116
|
-
* @param cursor The cursor to next batch. If blank, first batch is fetched
|
|
117
|
-
*/
|
|
118
|
-
async getUserFollowers(userId: string, count: number, cursor: string): Promise<CursoredData<User>> {
|
|
119
|
-
// If user is not authenticated, abort
|
|
120
|
-
if(!this.isAuthenticated) {
|
|
121
|
-
return { error: new Error('Cannot fetch user followers without authentication!') };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* When fetching list of followers, the official Twitter API seems to be fetching n + 20 followers,
|
|
126
|
-
* where n is the actual required number of followers.
|
|
127
|
-
* So changing count to count - 20, fixes fetching more than required number of follower
|
|
128
|
-
*/
|
|
129
|
-
// Fetching the raw data
|
|
130
|
-
let res = await this.request<RawUserFollowers>(Urls.userFollowersUrl(userId, (count > 20) ? (count - 20) : count, cursor)).then(res => res.data);
|
|
131
|
-
|
|
132
|
-
// Extracting data
|
|
133
|
-
let data = Extractors.extractUserFollow(res);
|
|
134
|
-
|
|
135
|
-
// Caching data
|
|
136
|
-
this.cacheData(data);
|
|
137
|
-
|
|
138
|
-
// Parsing data
|
|
139
|
-
let users = data.required.map(item => Deserializers.toUser(item));
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
list: users,
|
|
143
|
-
next: { value: data.cursor }
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* @returns The list of tweets liked by the target user
|
|
149
|
-
* @param userId The rest id of the target user
|
|
150
|
-
* @param count The batch size of the list
|
|
151
|
-
* @param cursor The cursor to next batch. If blank, first batch is fetched
|
|
152
|
-
*/
|
|
153
|
-
async getUserLikes(userId: string, count: number, cursor: string): Promise<CursoredData<Tweet>> {
|
|
154
|
-
// If user is not authenticated, abort
|
|
155
|
-
if(!this.isAuthenticated) {
|
|
156
|
-
return { error: new Error('Cannot fetch user likes without authentication!') };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Fetching the raw data
|
|
160
|
-
let res = await this.request<RawUserLikes>(Urls.userLikesUrl(userId, count, cursor)).then(res => res.data);
|
|
161
|
-
|
|
162
|
-
// Extracting data
|
|
163
|
-
let data = Extractors.extractUserLikes(res);
|
|
164
|
-
|
|
165
|
-
// Caching data
|
|
166
|
-
this.cacheData(data);
|
|
167
|
-
|
|
168
|
-
// Parsing data
|
|
169
|
-
let tweets = data.required.map(item => Deserializers.toTweet(item));
|
|
170
|
-
|
|
171
|
-
return {
|
|
172
|
-
list: tweets,
|
|
173
|
-
next: { value: data.cursor }
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
};
|
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
// TYPES
|
|
2
|
-
import { DataErrors } from '../../types/graphql/Errors';
|
|
3
|
-
import RawUser from '../../types/raw/user/User';
|
|
4
|
-
import RawUserFollowers from '../../types/raw/user/Followers';
|
|
5
|
-
import RawUserFollowing from '../../types/raw/user/Following';
|
|
6
|
-
import RawUserLikes from '../../types/raw/user/Likes';
|
|
7
|
-
import RawUserTweets from '../../types/raw/user/Tweets';
|
|
8
|
-
import RawTweet from '../../types/raw/tweet/Tweet';
|
|
9
|
-
import RawTweets from '../../types/raw/tweet/Tweets';
|
|
10
|
-
import RawLikers from '../../types/raw/tweet/Favouriters';
|
|
11
|
-
import RawRetweeters from '../../types/raw/tweet/Retweeters';
|
|
12
|
-
|
|
13
|
-
// PARSERS
|
|
14
|
-
import * as Parsers from './Parser';
|
|
15
|
-
|
|
16
|
-
/* USERS */
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @returns The raw user account data formatted and sorted into required and additional data
|
|
20
|
-
* @param res The raw response received from Twitter
|
|
21
|
-
*/
|
|
22
|
-
export function extractUserAccountDetails(res: RawUser): {
|
|
23
|
-
required: any[],
|
|
24
|
-
cursor: string,
|
|
25
|
-
users: any[],
|
|
26
|
-
tweets: any[]
|
|
27
|
-
} {
|
|
28
|
-
let required: any[] = []; // To store the reqruied raw data
|
|
29
|
-
let cursor: string = ''; // To store the cursor to next batch
|
|
30
|
-
let users: any[] = []; // To store additional user data
|
|
31
|
-
let tweets: any[] = []; // To store additional tweet data
|
|
32
|
-
|
|
33
|
-
// If user not found or account suspended
|
|
34
|
-
if (Parsers.isJSONEmpty(res.data) || Parsers.isJSONEmpty(res.data.user) || res.data.user.result.__typename !== 'User') {
|
|
35
|
-
throw new Error(DataErrors.UserNotFound);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Destructuring user account data
|
|
39
|
-
required.push(res.data.user.result);
|
|
40
|
-
users.push(res.data.user.result);
|
|
41
|
-
|
|
42
|
-
// Returning the data
|
|
43
|
-
return {
|
|
44
|
-
required: required,
|
|
45
|
-
cursor: cursor,
|
|
46
|
-
users: users,
|
|
47
|
-
tweets: tweets
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @returns The raw user following/followers data formatted and sorted into required and additional data
|
|
53
|
-
* @param res The raw response received from TwitterAPI
|
|
54
|
-
*/
|
|
55
|
-
export function extractUserFollow(res: RawUserFollowers | RawUserFollowing): {
|
|
56
|
-
required: any[],
|
|
57
|
-
cursor: string,
|
|
58
|
-
users: any[],
|
|
59
|
-
tweets: any[]
|
|
60
|
-
} {
|
|
61
|
-
let required: any[] = []; // To store the reqruied raw data
|
|
62
|
-
let cursor: string = ''; // To store the cursor to next batch
|
|
63
|
-
let users: any[] = []; // To store additional user data
|
|
64
|
-
let tweets: any[] = []; // To store additional tweet data
|
|
65
|
-
|
|
66
|
-
// If user does not exist
|
|
67
|
-
if (Parsers.isJSONEmpty(res.data.user)) {
|
|
68
|
-
throw new Error(DataErrors.UserNotFound);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Extracting the raw list
|
|
72
|
-
res.data.user.result.timeline.timeline.instructions.forEach(item => {
|
|
73
|
-
if (item.type === 'TimelineAddEntries') {
|
|
74
|
-
// Destructuring data
|
|
75
|
-
item.entries?.forEach(entry => {
|
|
76
|
-
// If entry is of type user and user account exists
|
|
77
|
-
if (entry.entryId.indexOf('user') != -1 && entry.content.itemContent?.user_results.result.__typename ==='User') {
|
|
78
|
-
required.push(entry.content.itemContent.user_results.result);
|
|
79
|
-
users.push(entry.content.itemContent.user_results.result);
|
|
80
|
-
}
|
|
81
|
-
// If entry is of type cursor
|
|
82
|
-
else if (entry.entryId.indexOf('cursor-bottom') != -1) {
|
|
83
|
-
cursor = entry.content.value ?? '';
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// Returning the data
|
|
90
|
-
return {
|
|
91
|
-
required: required,
|
|
92
|
-
cursor: cursor,
|
|
93
|
-
users: users,
|
|
94
|
-
tweets: tweets
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @returns The raw user likes data formatted and sorted into required and additional data
|
|
100
|
-
* @param res The raw response received from TwitterAPI
|
|
101
|
-
*/
|
|
102
|
-
export function extractUserLikes(res: RawUserLikes): {
|
|
103
|
-
required: any[],
|
|
104
|
-
cursor: string,
|
|
105
|
-
users: any[],
|
|
106
|
-
tweets: any[]
|
|
107
|
-
} {
|
|
108
|
-
let required: any[] = []; // To store the reqruied raw data
|
|
109
|
-
let cursor: string = ''; // To store the cursor to next batch
|
|
110
|
-
let users: any[] = []; // To store additional user data
|
|
111
|
-
let tweets: any[] = []; // To store additional tweet data
|
|
112
|
-
|
|
113
|
-
// If user does not exist
|
|
114
|
-
if (Parsers.isJSONEmpty(res.data.user)) {
|
|
115
|
-
throw new Error(DataErrors.UserNotFound);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Extracting the raw list
|
|
119
|
-
res.data.user.result.timeline_v2.timeline.instructions.forEach(item => {
|
|
120
|
-
if (item.type === 'TimelineAddEntries') {
|
|
121
|
-
// Destructuring data
|
|
122
|
-
item.entries.forEach(entry => {
|
|
123
|
-
// If entry is of type tweet and tweet exists
|
|
124
|
-
if (entry.entryId.indexOf('tweet') != -1 && entry.content.itemContent?.tweet_results.result.__typename === 'Tweet') {
|
|
125
|
-
required.push(entry.content.itemContent.tweet_results.result);
|
|
126
|
-
users.push(entry.content.itemContent.tweet_results.result.core.user_results.result);
|
|
127
|
-
tweets.push(entry.content.itemContent.tweet_results.result);
|
|
128
|
-
}
|
|
129
|
-
// If entry is of type cursor
|
|
130
|
-
else if (entry.entryId.indexOf('cursor-bottom') != -1) {
|
|
131
|
-
cursor = entry.content.value ?? '';
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// Returning the data
|
|
138
|
-
return {
|
|
139
|
-
required: required,
|
|
140
|
-
cursor: cursor,
|
|
141
|
-
users: users,
|
|
142
|
-
tweets: tweets
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @returns The raw tweets data formatted and sorted into required and additional data
|
|
148
|
-
* @param res The raw response received from TwitterAPI
|
|
149
|
-
*/
|
|
150
|
-
export function extractUserTweets(res: RawUserTweets): {
|
|
151
|
-
required: any[],
|
|
152
|
-
cursor: string,
|
|
153
|
-
users: any[],
|
|
154
|
-
tweets: any[]
|
|
155
|
-
} {
|
|
156
|
-
let required: any[] = []; // To store the reqruied raw data
|
|
157
|
-
let cursor: string = ''; // To store the cursor to next batch
|
|
158
|
-
let users: any[] = []; // To store additional user data
|
|
159
|
-
let tweets: any[] = []; // To store additional tweet data
|
|
160
|
-
|
|
161
|
-
// Getting the raw tweet list
|
|
162
|
-
let dataTweets = res.data.user.result.timeline_v2.timeline.instructions.filter(item => item.type === 'TimelineAddEntries')[0].entries;
|
|
163
|
-
|
|
164
|
-
// Destructuring tweets, if not empty
|
|
165
|
-
if (!Parsers.isJSONEmpty(dataTweets)) {
|
|
166
|
-
// Iterating through the json array of tweets
|
|
167
|
-
for (let entry of dataTweets) {
|
|
168
|
-
// If the entry is a tweet
|
|
169
|
-
if(entry.entryId.indexOf('tweet') != -1) {
|
|
170
|
-
required.push(entry.content.itemContent?.tweet_results.result);
|
|
171
|
-
tweets.push(entry.content.itemContent?.tweet_results.result);
|
|
172
|
-
users.push(entry.content.itemContent?.tweet_results.result.core.user_results.result);
|
|
173
|
-
}
|
|
174
|
-
// If the entry is a cursor
|
|
175
|
-
else if(entry.entryId.indexOf('cursor-bottom') != -1) {
|
|
176
|
-
cursor = entry.content.value as string;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return {
|
|
182
|
-
required: required,
|
|
183
|
-
cursor: cursor,
|
|
184
|
-
users: users,
|
|
185
|
-
tweets: tweets
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/* TWEETS */
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* @returns The raw tweets data formatted and sorted into required and additional data
|
|
193
|
-
* @param res The raw response received from TwitterAPI
|
|
194
|
-
*/
|
|
195
|
-
export function extractTweets(res: RawTweets): {
|
|
196
|
-
required: any[],
|
|
197
|
-
cursor: string,
|
|
198
|
-
users: any[],
|
|
199
|
-
tweets: any[]
|
|
200
|
-
} {
|
|
201
|
-
let required: any[] = []; // To store the reqruied raw data
|
|
202
|
-
let cursor: string = ''; // To store the cursor to next batch
|
|
203
|
-
let users: any[] = []; // To store additional user data
|
|
204
|
-
let tweets: any[] = []; // To store additional tweet data
|
|
205
|
-
|
|
206
|
-
// Getting raw tweet list
|
|
207
|
-
let dataTweets = res.globalObjects.tweets;
|
|
208
|
-
|
|
209
|
-
// Getting raw users list
|
|
210
|
-
let dataUsers = res.globalObjects.users;
|
|
211
|
-
|
|
212
|
-
// Destructuring tweets, if not empty
|
|
213
|
-
if (!Parsers.isJSONEmpty(dataTweets)) {
|
|
214
|
-
// Iterating through the json array of tweets
|
|
215
|
-
for (let key of Object.keys(dataTweets)) {
|
|
216
|
-
required.push({ rest_id: dataTweets[key].id_str, legacy: dataTweets[key] });
|
|
217
|
-
tweets.push({ rest_id: dataTweets[key].id_str, legacy: dataTweets[key] });
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Destructuring users, if not empty
|
|
222
|
-
if (!Parsers.isJSONEmpty(dataUsers)) {
|
|
223
|
-
// Iterating through the json array of users
|
|
224
|
-
for (let key of Object.keys(dataUsers)) {
|
|
225
|
-
users.push({ rest_id: dataUsers[key].id_str, legacy: dataUsers[key] });
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Getting the cursor to next batch
|
|
230
|
-
// If not first batch
|
|
231
|
-
if (res.timeline.instructions.length > 2) {
|
|
232
|
-
cursor = res.timeline.instructions[2]?.replaceEntry.entry.content.operation?.cursor.value ?? '';
|
|
233
|
-
}
|
|
234
|
-
// If first batch
|
|
235
|
-
else {
|
|
236
|
-
cursor = res.timeline.instructions[0].addEntries?.entries.filter(item => item.entryId.indexOf('cursor-bottom') != -1)[0].content.operation?.cursor.value ?? '';
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Returning the data
|
|
240
|
-
return {
|
|
241
|
-
required: required,
|
|
242
|
-
cursor: cursor,
|
|
243
|
-
users: users,
|
|
244
|
-
tweets: tweets
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* @returns The raw tweet data formatted and sorted into required and additional data
|
|
250
|
-
* @param res The raw response received from TwitterAPI
|
|
251
|
-
* @param tweetId The rest id of the tweet to fetch
|
|
252
|
-
*/
|
|
253
|
-
export function extractTweet(res: RawTweet, tweetId: string): {
|
|
254
|
-
required: any[],
|
|
255
|
-
cursor: string,
|
|
256
|
-
users: any[],
|
|
257
|
-
tweets: any[]
|
|
258
|
-
} {
|
|
259
|
-
let required: any[] = []; // To store the reqruied raw data
|
|
260
|
-
let cursor: string = ''; // To store the cursor to next batch
|
|
261
|
-
let users: any[] = []; // To store additional user data
|
|
262
|
-
let tweets: any[] = []; // To store additional tweet data
|
|
263
|
-
|
|
264
|
-
// If tweet does not exist
|
|
265
|
-
if (Parsers.isJSONEmpty(res.data)) {
|
|
266
|
-
throw new Error(DataErrors.TweetNotFound);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// Destructuring the received raw data
|
|
270
|
-
res.data.threaded_conversation_with_injections_v2.instructions.filter(item => item['type'] === 'TimelineAddEntries')[0].entries?.forEach(entry => {
|
|
271
|
-
// If entry is of type tweet and tweet exists
|
|
272
|
-
if (entry.entryId.indexOf('tweet') != -1 && entry.content.itemContent?.tweet_results?.result.__typename === 'Tweet') {
|
|
273
|
-
// If this is the required tweet
|
|
274
|
-
if (entry.entryId.indexOf(tweetId) != -1) {
|
|
275
|
-
required.push(entry.content.itemContent.tweet_results.result);
|
|
276
|
-
}
|
|
277
|
-
tweets.push(entry.content.itemContent.tweet_results.result);
|
|
278
|
-
users.push(entry.content.itemContent.tweet_results.result.core.user_results.result);
|
|
279
|
-
}
|
|
280
|
-
// If entry if of type conversation
|
|
281
|
-
else if (entry.entryId.indexOf('conversationthread') != -1) {
|
|
282
|
-
// Iterating over the conversation
|
|
283
|
-
entry.content.items?.forEach(item => {
|
|
284
|
-
// If item is of type tweet and tweet exists
|
|
285
|
-
if (item.entryId.indexOf('tweet') != -1 && item.item.itemContent.tweet_results?.result.__typename === 'Tweet') {
|
|
286
|
-
required.push(item.item.itemContent.tweet_results.result);
|
|
287
|
-
tweets.push(item.item.itemContent.tweet_results.result);
|
|
288
|
-
users.push(item.item.itemContent.tweet_results.result.core.user_results.result);
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
// Returning the data
|
|
295
|
-
return {
|
|
296
|
-
required: required,
|
|
297
|
-
cursor: cursor,
|
|
298
|
-
users: users,
|
|
299
|
-
tweets: tweets
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* @returns The raw tweet likers data formatted and sorted into required and additional data
|
|
305
|
-
* @param res The raw response received from TwitterAPI
|
|
306
|
-
*/
|
|
307
|
-
export function extractTweetLikers(res: RawLikers): {
|
|
308
|
-
required: any[],
|
|
309
|
-
cursor: string,
|
|
310
|
-
users: any[],
|
|
311
|
-
tweets: any[]
|
|
312
|
-
} {
|
|
313
|
-
let required: any[] = []; // To store the reqruied raw data
|
|
314
|
-
let cursor: string = ''; // To store the cursor to next batch
|
|
315
|
-
let users: any[] = []; // To store additional user data
|
|
316
|
-
let tweets: any[] = []; // To store additional tweet data
|
|
317
|
-
|
|
318
|
-
// If tweet does not exist
|
|
319
|
-
if (Parsers.isJSONEmpty(res.data.favoriters_timeline)) {
|
|
320
|
-
throw new Error(DataErrors.TweetNotFound);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// Destructuring raw list of likers
|
|
324
|
-
res.data.favoriters_timeline.timeline.instructions.filter(item => item.type === 'TimelineAddEntries')[0].entries.forEach(entry => {
|
|
325
|
-
// If entry is of type user and user exists
|
|
326
|
-
if (entry.entryId.indexOf('user') != -1 && entry.content.itemContent?.user_results.result.__typename === 'User') {
|
|
327
|
-
required.push(entry.content.itemContent.user_results.result);
|
|
328
|
-
users.push(entry.content.itemContent.user_results.result);
|
|
329
|
-
}
|
|
330
|
-
// If entry is of type cursor
|
|
331
|
-
else if (entry.entryId.indexOf('cursor-bottom') != -1) {
|
|
332
|
-
cursor = entry.content.value ?? '';
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
// Returning the data
|
|
337
|
-
return {
|
|
338
|
-
required: required,
|
|
339
|
-
cursor: cursor,
|
|
340
|
-
users: users,
|
|
341
|
-
tweets: tweets
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* @returns The raw tweet retweeters data formatted and sorted into required and additional data
|
|
347
|
-
* @param res The raw response received from TwitterAPI
|
|
348
|
-
*/
|
|
349
|
-
export function extractTweetRetweeters(res: RawRetweeters): {
|
|
350
|
-
required: any[],
|
|
351
|
-
cursor: string,
|
|
352
|
-
users: any[],
|
|
353
|
-
tweets: any[]
|
|
354
|
-
} {
|
|
355
|
-
let required: any[] = []; // To store the reqruied raw data
|
|
356
|
-
let cursor: string = ''; // To store the cursor to next batch
|
|
357
|
-
let users: any[] = []; // To store additional user data
|
|
358
|
-
let tweets: any[] = []; // To store additional tweet data
|
|
359
|
-
|
|
360
|
-
// If tweet does not exist
|
|
361
|
-
if (Parsers.isJSONEmpty(res.data.retweeters_timeline)) {
|
|
362
|
-
throw new Error(DataErrors.TweetNotFound);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// Destructuring raw list of retweeters
|
|
366
|
-
res.data.retweeters_timeline.timeline.instructions.filter(item => item.type === 'TimelineAddEntries')[0].entries.forEach(entry => {
|
|
367
|
-
// If entry is of type user and user exists
|
|
368
|
-
if (entry.entryId.indexOf('user') != -1 && entry.content.itemContent?.user_results.result.__typename === 'User') {
|
|
369
|
-
required.push(entry.content.itemContent.user_results.result);
|
|
370
|
-
users.push(entry.content.itemContent.user_results.result);
|
|
371
|
-
}
|
|
372
|
-
// If entry is of type cursor
|
|
373
|
-
else if (entry.entryId.indexOf('cursor-bottom') != -1) {
|
|
374
|
-
cursor = entry.content.value ?? '';
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
// Returning the data
|
|
379
|
-
return {
|
|
380
|
-
required: required,
|
|
381
|
-
cursor: cursor,
|
|
382
|
-
users: users,
|
|
383
|
-
tweets: tweets
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* @returns The raw tweet replies data formatted and sorted into required and additional data
|
|
389
|
-
* @param res The raw response received from TwitterAPI
|
|
390
|
-
* @param tweetId The id of the tweet whose replies must be extracted
|
|
391
|
-
*/
|
|
392
|
-
export function extractTweetReplies(res: RawTweet, tweetId: string): {
|
|
393
|
-
required: any[],
|
|
394
|
-
cursor: string,
|
|
395
|
-
users: any[],
|
|
396
|
-
tweets: any[]
|
|
397
|
-
} {
|
|
398
|
-
let required: any[] = []; // To store the reqruied raw data
|
|
399
|
-
let cursor: string = ''; // To store the cursor to next batch
|
|
400
|
-
let users: any[] = []; // To store additional user data
|
|
401
|
-
let tweets: any[] = []; // To store additional tweet data
|
|
402
|
-
|
|
403
|
-
// If tweet does not exist
|
|
404
|
-
if (Parsers.isJSONEmpty(res.data)) {
|
|
405
|
-
throw new Error(DataErrors.TweetNotFound);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// Destructuring the received raw data
|
|
409
|
-
//@ts-ignore
|
|
410
|
-
res.data.threaded_conversation_with_injections.instructions.filter(item => item.type === 'TimelineAddEntries')[0].entries.map(entry => {
|
|
411
|
-
// If entry is of type tweet
|
|
412
|
-
if (entry.entryId.indexOf('tweet') != -1) {
|
|
413
|
-
// If tweet exists
|
|
414
|
-
if(entry.content.itemContent?.tweet_results?.result.__typename === 'Tweet') {
|
|
415
|
-
tweets.push(entry.content.itemContent.tweet_results.result);
|
|
416
|
-
users.push(entry.content.itemContent.tweet_results.result.core.user_results.result);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
// If entry if of type conversation/reply
|
|
420
|
-
else if (entry.entryId.indexOf('conversationthread') != -1) {
|
|
421
|
-
// If tweet exists
|
|
422
|
-
if(entry.content.items?.at(0)?.item.itemContent.tweet_results?.result.__typename === 'Tweet') {
|
|
423
|
-
// Adding the 1st entry, which is a reply, to required list
|
|
424
|
-
required.push(entry.content.items[0].item.itemContent.tweet_results?.result);
|
|
425
|
-
tweets.push(entry.content.items[0].item.itemContent.tweet_results?.result);
|
|
426
|
-
users.push(entry.content.items[0].item.itemContent.tweet_results?.result.core.user_results.result);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// Iterating over the rest of the conversation
|
|
430
|
-
//@ts-ignore
|
|
431
|
-
entry.content.items.forEach(item => {
|
|
432
|
-
// If item is of type tweet
|
|
433
|
-
if (item.entryId.indexOf('tweet') != -1) {
|
|
434
|
-
// If tweet exists
|
|
435
|
-
if(item.item.itemContent.tweet_results?.result.__typename === 'Tweet') {
|
|
436
|
-
tweets.push(item.item.itemContent.tweet_results.result);
|
|
437
|
-
users.push(item.item.itemContent.tweet_results.result.core.user_results.result);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
// If entry is of type bottom cursor
|
|
443
|
-
else if (entry.entryId.indexOf('cursor-bottom') != -1) {
|
|
444
|
-
cursor = entry.content.itemContent?.value ?? '';
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
// Returning the data
|
|
449
|
-
return {
|
|
450
|
-
required: required,
|
|
451
|
-
cursor: cursor,
|
|
452
|
-
users: users,
|
|
453
|
-
tweets: tweets
|
|
454
|
-
};
|
|
455
|
-
}
|