rettiwt-api 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.dockerignore +1 -1
  2. package/dist/graphql/resolvers/TweetResolver.d.ts +0 -9
  3. package/dist/graphql/resolvers/TweetResolver.js +0 -48
  4. package/dist/graphql/resolvers/TweetResolver.js.map +1 -1
  5. package/dist/graphql/types/TweetTypes.js +12 -6
  6. package/dist/graphql/types/TweetTypes.js.map +1 -1
  7. package/dist/index.d.ts +2 -0
  8. package/dist/services/data/TweetService.d.ts +0 -6
  9. package/dist/services/data/TweetService.js +0 -30
  10. package/dist/services/data/TweetService.js.map +1 -1
  11. package/package.json +1 -1
  12. package/src/graphql/resolvers/TweetResolver.ts +5 -0
  13. package/src/graphql/types/TweetTypes.ts +7 -1
  14. package/src/index.ts +5 -1
  15. package/src/services/data/TweetService.ts +5 -0
  16. package/dist/services/data/UserAccountService.d.ts +0 -42
  17. package/dist/services/data/UserAccountService.js +0 -253
  18. package/dist/services/data/UserAccountService.js.map +0 -1
  19. package/dist/services/helper/Deserializers.d.ts +0 -19
  20. package/dist/services/helper/Deserializers.js +0 -115
  21. package/dist/services/helper/Deserializers.js.map +0 -1
  22. package/dist/services/helper/Extractors.d.ts +0 -101
  23. package/dist/services/helper/Extractors.js +0 -409
  24. package/dist/services/helper/Extractors.js.map +0 -1
  25. package/dist/services/helper/Urls.d.ts +0 -74
  26. package/dist/services/helper/Urls.js +0 -130
  27. package/dist/services/helper/Urls.js.map +0 -1
  28. package/dist/services/helper/deserializers/User.d.ts +0 -0
  29. package/dist/services/helper/deserializers/User.js +0 -2
  30. package/dist/services/helper/deserializers/User.js.map +0 -1
  31. package/dist/services/helper/extractors/TweetExtractors.d.ts +0 -0
  32. package/dist/services/helper/extractors/TweetExtractors.js +0 -2
  33. package/dist/services/helper/extractors/TweetExtractors.js.map +0 -1
  34. package/dist/services/helper/extractors/UserExtractors.d.ts +0 -45
  35. package/dist/services/helper/extractors/UserExtractors.js +0 -176
  36. package/dist/services/helper/extractors/UserExtractors.js.map +0 -1
  37. package/dist/services/helper/urls/Urls.d.ts +0 -4
  38. package/dist/services/helper/urls/Urls.js +0 -11
  39. package/dist/services/helper/urls/Urls.js.map +0 -1
  40. package/dist/types/Errors.d.ts +0 -15
  41. package/dist/types/Errors.js +0 -23
  42. package/dist/types/Errors.js.map +0 -1
  43. package/dist/types/Service.d.ts +0 -30
  44. package/dist/types/Service.js +0 -19
  45. package/dist/types/Service.js.map +0 -1
  46. package/dist/types/Tweet.d.ts +0 -41
  47. package/dist/types/Tweet.js +0 -5
  48. package/dist/types/Tweet.js.map +0 -1
  49. package/dist/types/User.d.ts +0 -19
  50. package/dist/types/User.js +0 -4
  51. package/dist/types/User.js.map +0 -1
  52. package/dist/types/UserAccount.d.ts +0 -19
  53. package/dist/types/UserAccount.js +0 -4
  54. package/dist/types/UserAccount.js.map +0 -1
  55. package/dist/types/raw/http/Error.d.ts +0 -34
  56. package/dist/types/raw/http/Error.js +0 -3
  57. package/dist/types/raw/http/Error.js.map +0 -1
  58. package/dist/types/raw/http/Response.d.ts +0 -34
  59. package/dist/types/raw/http/Response.js +0 -3
  60. package/dist/types/raw/http/Response.js.map +0 -1
  61. package/dist/types/raw/user/Tweets.d.ts +0 -2428
  62. package/dist/types/raw/user/Tweets.js +0 -3
  63. package/dist/types/raw/user/Tweets.js.map +0 -1
@@ -1,19 +0,0 @@
1
- import { User } from '../../types/UserAccount';
2
- import { Tweet, TweetEntities } from '../../types/Tweet';
3
- import { Result as RawUser } from '../../types/raw/user/User';
4
- import { Result as RawTweet, Entities2 as RawTweetEntities } from '../../types/raw/tweet/Tweet';
5
- /**
6
- * @returns A User object containing the user details
7
- * @param data The raw user data from Twitter API
8
- */
9
- export declare function toUser(data: RawUser): User;
10
- /**
11
- * @returns A TweetEntities object containing the various tweet entities
12
- * @param data The raw tweet entities data from the response received from TwitterAPI
13
- */
14
- export declare function toTweetEntities(data: RawTweetEntities): TweetEntities;
15
- /**
16
- * @returns A Tweet object containing the tweet data
17
- * @param data The raw tweet data from the response received from TwitterAPI
18
- */
19
- export declare function toTweet(data: RawTweet): Tweet;
@@ -1,115 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- exports.__esModule = true;
26
- exports.toTweet = exports.toTweetEntities = exports.toUser = void 0;
27
- // PARSERS
28
- var Parsers = __importStar(require("./Parser"));
29
- /**
30
- * @returns A User object containing the user details
31
- * @param data The raw user data from Twitter API
32
- */
33
- function toUser(data) {
34
- return {
35
- id: data.rest_id,
36
- userName: data.legacy.screen_name,
37
- fullName: data.legacy.name,
38
- createdAt: data.legacy.created_at,
39
- description: data.legacy.description,
40
- isVerified: data.legacy.verified,
41
- favouritesCount: data.legacy.favourites_count,
42
- followersCount: data.legacy.followers_count,
43
- followingsCount: data.legacy.friends_count,
44
- statusesCount: data.legacy.statuses_count,
45
- location: data.legacy.location,
46
- pinnedTweet: data.legacy.pinned_tweet_ids_str[0],
47
- profileBanner: data.legacy.profile_banner_url,
48
- profileImage: data.legacy.profile_image_url_https
49
- };
50
- }
51
- exports.toUser = toUser;
52
- /**
53
- * @returns A TweetEntities object containing the various tweet entities
54
- * @param data The raw tweet entities data from the response received from TwitterAPI
55
- */
56
- function toTweetEntities(data) {
57
- var entities = {
58
- mentionedUsers: [],
59
- urls: [],
60
- media: [],
61
- hashtags: []
62
- };
63
- // Extracting user mentions
64
- if (data.user_mentions) {
65
- for (var _i = 0, _a = data.user_mentions; _i < _a.length; _i++) {
66
- var user = _a[_i];
67
- entities.mentionedUsers.push(user.id_str);
68
- }
69
- }
70
- // Extracting urls
71
- if (data.urls) {
72
- for (var _b = 0, _c = data.urls; _b < _c.length; _b++) {
73
- var url = _c[_b];
74
- entities.urls.push(url.expanded_url);
75
- }
76
- }
77
- // Extracting hashtags
78
- if (data.hashtags) {
79
- for (var _d = 0, _e = data.hashtags; _d < _e.length; _d++) {
80
- var hashtag = _e[_d];
81
- entities.hashtags.push(hashtag.text);
82
- }
83
- }
84
- // Extracting media urls (if any)
85
- if (data.media) {
86
- for (var _f = 0, _g = data.media; _f < _g.length; _f++) {
87
- var media = _g[_f];
88
- entities.media.push(media.media_url_https);
89
- }
90
- }
91
- return entities;
92
- }
93
- exports.toTweetEntities = toTweetEntities;
94
- /**
95
- * @returns A Tweet object containing the tweet data
96
- * @param data The raw tweet data from the response received from TwitterAPI
97
- */
98
- function toTweet(data) {
99
- return {
100
- id: data.rest_id,
101
- createdAt: data.legacy.created_at,
102
- tweetBy: data.legacy.user_id_str,
103
- entities: toTweetEntities(data.legacy.entities),
104
- quoted: data.legacy.quoted_status_id_str,
105
- fullText: Parsers.normalizeText(data.legacy.full_text),
106
- replyTo: data.legacy.in_reply_to_status_id_str,
107
- lang: data.legacy.lang,
108
- quoteCount: data.legacy.quote_count,
109
- replyCount: data.legacy.reply_count,
110
- retweetCount: data.legacy.retweet_count,
111
- likeCount: data.legacy.favorite_count
112
- };
113
- }
114
- exports.toTweet = toTweet;
115
- //# sourceMappingURL=Deserializers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Deserializers.js","sourceRoot":"","sources":["../../../src/services/helper/Deserializers.ts"],"names":[],"mappings":"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"}
@@ -1,101 +0,0 @@
1
- import RawUser from '../../types/raw/user/User';
2
- import RawUserFollowers from '../../types/raw/user/Followers';
3
- import RawUserFollowing from '../../types/raw/user/Following';
4
- import RawUserLikes from '../../types/raw/user/Likes';
5
- import RawUserTweets from '../../types/raw/user/Tweets';
6
- import RawTweet from '../../types/raw/tweet/Tweet';
7
- import RawTweets from '../../types/raw/tweet/Tweets';
8
- import RawLikers from '../../types/raw/tweet/Favouriters';
9
- import RawRetweeters from '../../types/raw/tweet/Retweeters';
10
- /**
11
- * @returns The raw user account data formatted and sorted into required and additional data
12
- * @param res The raw response received from Twitter
13
- */
14
- export declare function extractUserAccountDetails(res: RawUser): {
15
- required: any[];
16
- cursor: string;
17
- users: any[];
18
- tweets: any[];
19
- };
20
- /**
21
- * @returns The raw user following/followers data formatted and sorted into required and additional data
22
- * @param res The raw response received from TwitterAPI
23
- */
24
- export declare function extractUserFollow(res: RawUserFollowers | RawUserFollowing): {
25
- required: any[];
26
- cursor: string;
27
- users: any[];
28
- tweets: any[];
29
- };
30
- /**
31
- * @returns The raw user likes data formatted and sorted into required and additional data
32
- * @param res The raw response received from TwitterAPI
33
- */
34
- export declare function extractUserLikes(res: RawUserLikes): {
35
- required: any[];
36
- cursor: string;
37
- users: any[];
38
- tweets: any[];
39
- };
40
- /**
41
- * @returns The raw tweets data formatted and sorted into required and additional data
42
- * @param res The raw response received from TwitterAPI
43
- */
44
- export declare function extractUserTweets(res: RawUserTweets): {
45
- required: any[];
46
- cursor: string;
47
- users: any[];
48
- tweets: any[];
49
- };
50
- /**
51
- * @returns The raw tweets data formatted and sorted into required and additional data
52
- * @param res The raw response received from TwitterAPI
53
- */
54
- export declare function extractTweets(res: RawTweets): {
55
- required: any[];
56
- cursor: string;
57
- users: any[];
58
- tweets: any[];
59
- };
60
- /**
61
- * @returns The raw tweet data formatted and sorted into required and additional data
62
- * @param res The raw response received from TwitterAPI
63
- * @param tweetId The rest id of the tweet to fetch
64
- */
65
- export declare function extractTweet(res: RawTweet, tweetId: string): {
66
- required: any[];
67
- cursor: string;
68
- users: any[];
69
- tweets: any[];
70
- };
71
- /**
72
- * @returns The raw tweet likers data formatted and sorted into required and additional data
73
- * @param res The raw response received from TwitterAPI
74
- */
75
- export declare function extractTweetLikers(res: RawLikers): {
76
- required: any[];
77
- cursor: string;
78
- users: any[];
79
- tweets: any[];
80
- };
81
- /**
82
- * @returns The raw tweet retweeters data formatted and sorted into required and additional data
83
- * @param res The raw response received from TwitterAPI
84
- */
85
- export declare function extractTweetRetweeters(res: RawRetweeters): {
86
- required: any[];
87
- cursor: string;
88
- users: any[];
89
- tweets: any[];
90
- };
91
- /**
92
- * @returns The raw tweet replies data formatted and sorted into required and additional data
93
- * @param res The raw response received from TwitterAPI
94
- * @param tweetId The id of the tweet whose replies must be extracted
95
- */
96
- export declare function extractTweetReplies(res: RawTweet, tweetId: string): {
97
- required: any[];
98
- cursor: string;
99
- users: any[];
100
- tweets: any[];
101
- };
@@ -1,409 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- exports.__esModule = true;
26
- exports.extractTweetReplies = exports.extractTweetRetweeters = exports.extractTweetLikers = exports.extractTweet = exports.extractTweets = exports.extractUserTweets = exports.extractUserLikes = exports.extractUserFollow = exports.extractUserAccountDetails = void 0;
27
- // TYPES
28
- var Errors_1 = require("../../types/Errors");
29
- // PARSERS
30
- var Parsers = __importStar(require("./Parser"));
31
- /* USERS */
32
- /**
33
- * @returns The raw user account data formatted and sorted into required and additional data
34
- * @param res The raw response received from Twitter
35
- */
36
- function extractUserAccountDetails(res) {
37
- var required = []; // To store the reqruied raw data
38
- var cursor = ''; // To store the cursor to next batch
39
- var users = []; // To store additional user data
40
- var tweets = []; // To store additional tweet data
41
- // If user not found or account suspended
42
- if (Parsers.isJSONEmpty(res.data) || Parsers.isJSONEmpty(res.data.user) || res.data.user.result.__typename !== 'User') {
43
- throw new Error(Errors_1.DataErrors.UserNotFound);
44
- }
45
- // Destructuring user account data
46
- required.push(res.data.user.result);
47
- users.push(res.data.user.result);
48
- // Returning the data
49
- return {
50
- required: required,
51
- cursor: cursor,
52
- users: users,
53
- tweets: tweets
54
- };
55
- }
56
- exports.extractUserAccountDetails = extractUserAccountDetails;
57
- /**
58
- * @returns The raw user following/followers data formatted and sorted into required and additional data
59
- * @param res The raw response received from TwitterAPI
60
- */
61
- function extractUserFollow(res) {
62
- var required = []; // To store the reqruied raw data
63
- var cursor = ''; // To store the cursor to next batch
64
- var users = []; // To store additional user data
65
- var tweets = []; // To store additional tweet data
66
- // If user does not exist
67
- if (Parsers.isJSONEmpty(res.data.user)) {
68
- throw new Error(Errors_1.DataErrors.UserNotFound);
69
- }
70
- // Extracting the raw list
71
- res.data.user.result.timeline.timeline.instructions.forEach(function (item) {
72
- var _a;
73
- if (item.type === 'TimelineAddEntries') {
74
- // Destructuring data
75
- (_a = item.entries) === null || _a === void 0 ? void 0 : _a.forEach(function (entry) {
76
- var _a, _b;
77
- // If entry is of type user and user account exists
78
- if (entry.entryId.indexOf('user') != -1 && ((_a = entry.content.itemContent) === null || _a === void 0 ? void 0 : _a.user_results.result.__typename) === 'User') {
79
- required.push(entry.content.itemContent.user_results.result);
80
- users.push(entry.content.itemContent.user_results.result);
81
- }
82
- // If entry is of type cursor
83
- else if (entry.entryId.indexOf('cursor-bottom') != -1) {
84
- cursor = (_b = entry.content.value) !== null && _b !== void 0 ? _b : '';
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
- exports.extractUserFollow = extractUserFollow;
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
- function extractUserLikes(res) {
103
- var required = []; // To store the reqruied raw data
104
- var cursor = ''; // To store the cursor to next batch
105
- var users = []; // To store additional user data
106
- var tweets = []; // To store additional tweet data
107
- // If user does not exist
108
- if (Parsers.isJSONEmpty(res.data.user)) {
109
- throw new Error(Errors_1.DataErrors.UserNotFound);
110
- }
111
- // Extracting the raw list
112
- res.data.user.result.timeline_v2.timeline.instructions.forEach(function (item) {
113
- if (item.type === 'TimelineAddEntries') {
114
- // Destructuring data
115
- item.entries.forEach(function (entry) {
116
- var _a, _b;
117
- // If entry is of type tweet and tweet exists
118
- if (entry.entryId.indexOf('tweet') != -1 && ((_a = entry.content.itemContent) === null || _a === void 0 ? void 0 : _a.tweet_results.result.__typename) === 'Tweet') {
119
- required.push(entry.content.itemContent.tweet_results.result);
120
- users.push(entry.content.itemContent.tweet_results.result.core.user_results.result);
121
- tweets.push(entry.content.itemContent.tweet_results.result);
122
- }
123
- // If entry is of type cursor
124
- else if (entry.entryId.indexOf('cursor-bottom') != -1) {
125
- cursor = (_b = entry.content.value) !== null && _b !== void 0 ? _b : '';
126
- }
127
- });
128
- }
129
- });
130
- // Returning the data
131
- return {
132
- required: required,
133
- cursor: cursor,
134
- users: users,
135
- tweets: tweets
136
- };
137
- }
138
- exports.extractUserLikes = extractUserLikes;
139
- /**
140
- * @returns The raw tweets data formatted and sorted into required and additional data
141
- * @param res The raw response received from TwitterAPI
142
- */
143
- function extractUserTweets(res) {
144
- var _a, _b, _c;
145
- var required = []; // To store the reqruied raw data
146
- var cursor = ''; // To store the cursor to next batch
147
- var users = []; // To store additional user data
148
- var tweets = []; // To store additional tweet data
149
- // Getting the raw tweet list
150
- var dataTweets = res.data.user.result.timeline_v2.timeline.instructions.filter(function (item) { return item.type === 'TimelineAddEntries'; })[0].entries;
151
- // Destructuring tweets, if not empty
152
- if (!Parsers.isJSONEmpty(dataTweets)) {
153
- // Iterating through the json array of tweets
154
- for (var _i = 0, dataTweets_1 = dataTweets; _i < dataTweets_1.length; _i++) {
155
- var entry = dataTweets_1[_i];
156
- // If the entry is a tweet
157
- if (entry.entryId.indexOf('tweet') != -1) {
158
- required.push((_a = entry.content.itemContent) === null || _a === void 0 ? void 0 : _a.tweet_results.result);
159
- tweets.push((_b = entry.content.itemContent) === null || _b === void 0 ? void 0 : _b.tweet_results.result);
160
- users.push((_c = entry.content.itemContent) === null || _c === void 0 ? void 0 : _c.tweet_results.result.core.user_results.result);
161
- }
162
- // If the entry is a cursor
163
- else if (entry.entryId.indexOf('cursor-bottom') != -1) {
164
- cursor = entry.content.value;
165
- }
166
- }
167
- }
168
- return {
169
- required: required,
170
- cursor: cursor,
171
- users: users,
172
- tweets: tweets
173
- };
174
- }
175
- exports.extractUserTweets = extractUserTweets;
176
- /* TWEETS */
177
- /**
178
- * @returns The raw tweets data formatted and sorted into required and additional data
179
- * @param res The raw response received from TwitterAPI
180
- */
181
- function extractTweets(res) {
182
- var _a, _b, _c, _d, _e, _f;
183
- var required = []; // To store the reqruied raw data
184
- var cursor = ''; // To store the cursor to next batch
185
- var users = []; // To store additional user data
186
- var tweets = []; // To store additional tweet data
187
- // Getting raw tweet list
188
- var dataTweets = res.globalObjects.tweets;
189
- // Getting raw users list
190
- var dataUsers = res.globalObjects.users;
191
- // Destructuring tweets, if not empty
192
- if (!Parsers.isJSONEmpty(dataTweets)) {
193
- // Iterating through the json array of tweets
194
- for (var _i = 0, _g = Object.keys(dataTweets); _i < _g.length; _i++) {
195
- var key = _g[_i];
196
- required.push({ rest_id: dataTweets[key].id_str, legacy: dataTweets[key] });
197
- tweets.push({ rest_id: dataTweets[key].id_str, legacy: dataTweets[key] });
198
- }
199
- }
200
- // Destructuring users, if not empty
201
- if (!Parsers.isJSONEmpty(dataUsers)) {
202
- // Iterating through the json array of users
203
- for (var _h = 0, _j = Object.keys(dataUsers); _h < _j.length; _h++) {
204
- var key = _j[_h];
205
- users.push({ rest_id: dataUsers[key].id_str, legacy: dataUsers[key] });
206
- }
207
- }
208
- // Getting the cursor to next batch
209
- // If not first batch
210
- if (res.timeline.instructions.length > 2) {
211
- cursor = (_c = (_b = (_a = res.timeline.instructions[2]) === null || _a === void 0 ? void 0 : _a.replaceEntry.entry.content.operation) === null || _b === void 0 ? void 0 : _b.cursor.value) !== null && _c !== void 0 ? _c : '';
212
- }
213
- // If first batch
214
- else {
215
- cursor = (_f = (_e = (_d = res.timeline.instructions[0].addEntries) === null || _d === void 0 ? void 0 : _d.entries.filter(function (item) { return item.entryId.indexOf('cursor-bottom') != -1; })[0].content.operation) === null || _e === void 0 ? void 0 : _e.cursor.value) !== null && _f !== void 0 ? _f : '';
216
- }
217
- // Returning the data
218
- return {
219
- required: required,
220
- cursor: cursor,
221
- users: users,
222
- tweets: tweets
223
- };
224
- }
225
- exports.extractTweets = extractTweets;
226
- /**
227
- * @returns The raw tweet data formatted and sorted into required and additional data
228
- * @param res The raw response received from TwitterAPI
229
- * @param tweetId The rest id of the tweet to fetch
230
- */
231
- function extractTweet(res, tweetId) {
232
- var _a;
233
- var required = []; // To store the reqruied raw data
234
- var cursor = ''; // To store the cursor to next batch
235
- var users = []; // To store additional user data
236
- var tweets = []; // To store additional tweet data
237
- // If tweet does not exist
238
- if (Parsers.isJSONEmpty(res.data)) {
239
- throw new Error(Errors_1.DataErrors.TweetNotFound);
240
- }
241
- // Destructuring the received raw data
242
- (_a = res.data.threaded_conversation_with_injections_v2.instructions.filter(function (item) { return item['type'] === 'TimelineAddEntries'; })[0].entries) === null || _a === void 0 ? void 0 : _a.forEach(function (entry) {
243
- var _a, _b, _c;
244
- // If entry is of type tweet and tweet exists
245
- if (entry.entryId.indexOf('tweet') != -1 && ((_b = (_a = entry.content.itemContent) === null || _a === void 0 ? void 0 : _a.tweet_results) === null || _b === void 0 ? void 0 : _b.result.__typename) === 'Tweet') {
246
- // If this is the required tweet
247
- if (entry.entryId.indexOf(tweetId) != -1) {
248
- required.push(entry.content.itemContent.tweet_results.result);
249
- }
250
- tweets.push(entry.content.itemContent.tweet_results.result);
251
- users.push(entry.content.itemContent.tweet_results.result.core.user_results.result);
252
- }
253
- // If entry if of type conversation
254
- else if (entry.entryId.indexOf('conversationthread') != -1) {
255
- // Iterating over the conversation
256
- (_c = entry.content.items) === null || _c === void 0 ? void 0 : _c.forEach(function (item) {
257
- var _a;
258
- // If item is of type tweet and tweet exists
259
- if (item.entryId.indexOf('tweet') != -1 && ((_a = item.item.itemContent.tweet_results) === null || _a === void 0 ? void 0 : _a.result.__typename) === 'Tweet') {
260
- required.push(item.item.itemContent.tweet_results.result);
261
- tweets.push(item.item.itemContent.tweet_results.result);
262
- users.push(item.item.itemContent.tweet_results.result.core.user_results.result);
263
- }
264
- });
265
- }
266
- });
267
- // Returning the data
268
- return {
269
- required: required,
270
- cursor: cursor,
271
- users: users,
272
- tweets: tweets
273
- };
274
- }
275
- exports.extractTweet = extractTweet;
276
- /**
277
- * @returns The raw tweet likers data formatted and sorted into required and additional data
278
- * @param res The raw response received from TwitterAPI
279
- */
280
- function extractTweetLikers(res) {
281
- var required = []; // To store the reqruied raw data
282
- var cursor = ''; // To store the cursor to next batch
283
- var users = []; // To store additional user data
284
- var tweets = []; // To store additional tweet data
285
- // If tweet does not exist
286
- if (Parsers.isJSONEmpty(res.data.favoriters_timeline)) {
287
- throw new Error(Errors_1.DataErrors.TweetNotFound);
288
- }
289
- // Destructuring raw list of likers
290
- res.data.favoriters_timeline.timeline.instructions.filter(function (item) { return item.type === 'TimelineAddEntries'; })[0].entries.forEach(function (entry) {
291
- var _a, _b;
292
- // If entry is of type user and user exists
293
- if (entry.entryId.indexOf('user') != -1 && ((_a = entry.content.itemContent) === null || _a === void 0 ? void 0 : _a.user_results.result.__typename) === 'User') {
294
- required.push(entry.content.itemContent.user_results.result);
295
- users.push(entry.content.itemContent.user_results.result);
296
- }
297
- // If entry is of type cursor
298
- else if (entry.entryId.indexOf('cursor-bottom') != -1) {
299
- cursor = (_b = entry.content.value) !== null && _b !== void 0 ? _b : '';
300
- }
301
- });
302
- // Returning the data
303
- return {
304
- required: required,
305
- cursor: cursor,
306
- users: users,
307
- tweets: tweets
308
- };
309
- }
310
- exports.extractTweetLikers = extractTweetLikers;
311
- /**
312
- * @returns The raw tweet retweeters data formatted and sorted into required and additional data
313
- * @param res The raw response received from TwitterAPI
314
- */
315
- function extractTweetRetweeters(res) {
316
- var required = []; // To store the reqruied raw data
317
- var cursor = ''; // To store the cursor to next batch
318
- var users = []; // To store additional user data
319
- var tweets = []; // To store additional tweet data
320
- // If tweet does not exist
321
- if (Parsers.isJSONEmpty(res.data.retweeters_timeline)) {
322
- throw new Error(Errors_1.DataErrors.TweetNotFound);
323
- }
324
- // Destructuring raw list of retweeters
325
- res.data.retweeters_timeline.timeline.instructions.filter(function (item) { return item.type === 'TimelineAddEntries'; })[0].entries.forEach(function (entry) {
326
- var _a, _b;
327
- // If entry is of type user and user exists
328
- if (entry.entryId.indexOf('user') != -1 && ((_a = entry.content.itemContent) === null || _a === void 0 ? void 0 : _a.user_results.result.__typename) === 'User') {
329
- required.push(entry.content.itemContent.user_results.result);
330
- users.push(entry.content.itemContent.user_results.result);
331
- }
332
- // If entry is of type cursor
333
- else if (entry.entryId.indexOf('cursor-bottom') != -1) {
334
- cursor = (_b = entry.content.value) !== null && _b !== void 0 ? _b : '';
335
- }
336
- });
337
- // Returning the data
338
- return {
339
- required: required,
340
- cursor: cursor,
341
- users: users,
342
- tweets: tweets
343
- };
344
- }
345
- exports.extractTweetRetweeters = extractTweetRetweeters;
346
- /**
347
- * @returns The raw tweet replies data formatted and sorted into required and additional data
348
- * @param res The raw response received from TwitterAPI
349
- * @param tweetId The id of the tweet whose replies must be extracted
350
- */
351
- function extractTweetReplies(res, tweetId) {
352
- var required = []; // To store the reqruied raw data
353
- var cursor = ''; // To store the cursor to next batch
354
- var users = []; // To store additional user data
355
- var tweets = []; // To store additional tweet data
356
- // If tweet does not exist
357
- if (Parsers.isJSONEmpty(res.data)) {
358
- throw new Error(Errors_1.DataErrors.TweetNotFound);
359
- }
360
- // Destructuring the received raw data
361
- //@ts-ignore
362
- res.data.threaded_conversation_with_injections.instructions.filter(function (item) { return item.type === 'TimelineAddEntries'; })[0].entries.map(function (entry) {
363
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
364
- // If entry is of type tweet
365
- if (entry.entryId.indexOf('tweet') != -1) {
366
- // If tweet exists
367
- if (((_b = (_a = entry.content.itemContent) === null || _a === void 0 ? void 0 : _a.tweet_results) === null || _b === void 0 ? void 0 : _b.result.__typename) === 'Tweet') {
368
- tweets.push(entry.content.itemContent.tweet_results.result);
369
- users.push(entry.content.itemContent.tweet_results.result.core.user_results.result);
370
- }
371
- }
372
- // If entry if of type conversation/reply
373
- else if (entry.entryId.indexOf('conversationthread') != -1) {
374
- // If tweet exists
375
- if (((_e = (_d = (_c = entry.content.items) === null || _c === void 0 ? void 0 : _c.at(0)) === null || _d === void 0 ? void 0 : _d.item.itemContent.tweet_results) === null || _e === void 0 ? void 0 : _e.result.__typename) === 'Tweet') {
376
- // Adding the 1st entry, which is a reply, to required list
377
- required.push((_f = entry.content.items[0].item.itemContent.tweet_results) === null || _f === void 0 ? void 0 : _f.result);
378
- tweets.push((_g = entry.content.items[0].item.itemContent.tweet_results) === null || _g === void 0 ? void 0 : _g.result);
379
- users.push((_h = entry.content.items[0].item.itemContent.tweet_results) === null || _h === void 0 ? void 0 : _h.result.core.user_results.result);
380
- }
381
- // Iterating over the rest of the conversation
382
- //@ts-ignore
383
- entry.content.items.forEach(function (item) {
384
- var _a;
385
- // If item is of type tweet
386
- if (item.entryId.indexOf('tweet') != -1) {
387
- // If tweet exists
388
- if (((_a = item.item.itemContent.tweet_results) === null || _a === void 0 ? void 0 : _a.result.__typename) === 'Tweet') {
389
- tweets.push(item.item.itemContent.tweet_results.result);
390
- users.push(item.item.itemContent.tweet_results.result.core.user_results.result);
391
- }
392
- }
393
- });
394
- }
395
- // If entry is of type bottom cursor
396
- else if (entry.entryId.indexOf('cursor-bottom') != -1) {
397
- cursor = (_k = (_j = entry.content.itemContent) === null || _j === void 0 ? void 0 : _j.value) !== null && _k !== void 0 ? _k : '';
398
- }
399
- });
400
- // Returning the data
401
- return {
402
- required: required,
403
- cursor: cursor,
404
- users: users,
405
- tweets: tweets
406
- };
407
- }
408
- exports.extractTweetReplies = extractTweetReplies;
409
- //# sourceMappingURL=Extractors.js.map