rettiwt-api 1.1.1 → 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.
Files changed (274) hide show
  1. package/README.md +32 -7
  2. package/dist/endpoints/Endpoints.d.ts +14 -0
  3. package/dist/endpoints/Endpoints.js +20 -0
  4. package/dist/endpoints/Endpoints.js.map +1 -0
  5. package/dist/endpoints/Url.d.ts +5 -0
  6. package/dist/endpoints/Url.js +12 -0
  7. package/dist/endpoints/Url.js.map +1 -0
  8. package/dist/enums/Endpoints.d.ts +25 -0
  9. package/dist/enums/Endpoints.js +31 -0
  10. package/dist/enums/Endpoints.js.map +1 -0
  11. package/dist/enums/Errors.d.ts +20 -0
  12. package/dist/enums/Errors.js +28 -0
  13. package/dist/enums/Errors.js.map +1 -0
  14. package/dist/enums/HTTP.d.ts +17 -0
  15. package/dist/enums/HTTP.js +23 -0
  16. package/dist/enums/HTTP.js.map +1 -0
  17. package/dist/graphql/enums/Errors.d.ts +20 -0
  18. package/dist/graphql/enums/Errors.js +28 -0
  19. package/dist/graphql/enums/Errors.js.map +1 -0
  20. package/dist/graphql/queries/RootQuery.js +10 -3
  21. package/dist/graphql/queries/RootQuery.js.map +1 -1
  22. package/dist/graphql/resolvers/AccountResolver.d.ts +3 -3
  23. package/dist/graphql/resolvers/AccountResolver.js.map +1 -1
  24. package/dist/graphql/resolvers/ResolverBase.d.ts +14 -3
  25. package/dist/graphql/resolvers/ResolverBase.js +13 -1
  26. package/dist/graphql/resolvers/ResolverBase.js.map +1 -1
  27. package/dist/graphql/resolvers/TweetResolver.d.ts +3 -3
  28. package/dist/graphql/resolvers/TweetResolver.js +30 -18
  29. package/dist/graphql/resolvers/TweetResolver.js.map +1 -1
  30. package/dist/graphql/resolvers/UserResolver.d.ts +4 -4
  31. package/dist/graphql/resolvers/UserResolver.js +23 -19
  32. package/dist/graphql/resolvers/UserResolver.js.map +1 -1
  33. package/dist/graphql/types/Errors.d.ts +20 -0
  34. package/dist/graphql/types/Errors.js +28 -0
  35. package/dist/graphql/types/Errors.js.map +1 -0
  36. package/dist/graphql/types/TweetTypes.js +2 -2
  37. package/dist/graphql/types/TweetTypes.js.map +1 -1
  38. package/dist/index.d.ts +31 -15
  39. package/dist/index.js +32 -17
  40. package/dist/index.js.map +1 -1
  41. package/dist/middlewares/Authentication.d.ts +0 -0
  42. package/dist/middlewares/Authentication.js +2 -0
  43. package/dist/middlewares/Authentication.js.map +1 -0
  44. package/dist/models/args/TweetFilter.d.ts +59 -0
  45. package/dist/models/args/TweetFilter.js +101 -0
  46. package/dist/models/args/TweetFilter.js.map +1 -0
  47. package/dist/models/args/TweetListArgs.d.ts +21 -0
  48. package/dist/models/args/TweetListArgs.js +54 -0
  49. package/dist/models/args/TweetListArgs.js.map +1 -0
  50. package/dist/models/args/UserListArgs.d.ts +21 -0
  51. package/dist/models/args/UserListArgs.js +54 -0
  52. package/dist/models/args/UserListArgs.js.map +1 -0
  53. package/dist/models/auth/AuthCookie.d.ts +21 -0
  54. package/dist/models/auth/AuthCookie.js +33 -0
  55. package/dist/models/auth/AuthCookie.js.map +1 -0
  56. package/dist/models/data/CursoredData.d.ts +34 -0
  57. package/dist/models/data/CursoredData.js +42 -0
  58. package/dist/models/data/CursoredData.js.map +1 -0
  59. package/dist/models/data/DataValidationError.d.ts +18 -0
  60. package/dist/models/data/DataValidationError.js +21 -0
  61. package/dist/models/data/DataValidationError.js.map +1 -0
  62. package/dist/models/data/Errors.d.ts +18 -0
  63. package/dist/models/data/Errors.js +21 -0
  64. package/dist/models/data/Errors.js.map +1 -0
  65. package/dist/models/data/Service.d.ts +33 -0
  66. package/dist/models/data/Service.js +41 -0
  67. package/dist/models/data/Service.js.map +1 -0
  68. package/dist/models/data/Tweet.d.ts +53 -0
  69. package/dist/models/data/Tweet.js +104 -0
  70. package/dist/models/data/Tweet.js.map +1 -0
  71. package/dist/models/data/User.d.ts +41 -0
  72. package/dist/models/data/User.js +32 -0
  73. package/dist/models/data/User.js.map +1 -0
  74. package/dist/models/errors/DataValidationError.d.ts +20 -0
  75. package/dist/models/errors/DataValidationError.js +23 -0
  76. package/dist/models/errors/DataValidationError.js.map +1 -0
  77. package/dist/models/query/Variables.d.ts +2 -0
  78. package/dist/models/query/Variables.js +10 -0
  79. package/dist/models/query/Variables.js.map +1 -0
  80. package/dist/requests/Url.d.ts +5 -0
  81. package/dist/requests/Url.js +12 -0
  82. package/dist/requests/Url.js.map +1 -0
  83. package/dist/server.d.ts +1 -1
  84. package/dist/server.js +9 -10
  85. package/dist/server.js.map +1 -1
  86. package/dist/services/accounts/AccountService.d.ts +6 -0
  87. package/dist/services/accounts/AccountService.js +20 -0
  88. package/dist/services/accounts/AccountService.js.map +1 -1
  89. package/dist/services/auth/AccountService.d.ts +88 -0
  90. package/dist/services/auth/AccountService.js +392 -0
  91. package/dist/services/auth/AccountService.js.map +1 -0
  92. package/dist/services/auth/AuthService.d.ts +31 -0
  93. package/dist/services/auth/AuthService.js +118 -0
  94. package/dist/services/auth/AuthService.js.map +1 -0
  95. package/dist/services/auth/LoginFlows.d.ts +77 -0
  96. package/dist/services/auth/LoginFlows.js +92 -0
  97. package/dist/services/auth/LoginFlows.js.map +1 -0
  98. package/dist/services/data/TweetService.d.ts +46 -16
  99. package/dist/services/data/TweetService.js +71 -54
  100. package/dist/services/data/TweetService.js.map +1 -1
  101. package/dist/services/data/UserService.d.ts +45 -21
  102. package/dist/services/data/UserService.js +78 -75
  103. package/dist/services/data/UserService.js.map +1 -1
  104. package/dist/services/helper/Headers.d.ts +4 -4
  105. package/dist/services/helper/Headers.js.map +1 -1
  106. package/dist/services/helper/Parser.d.ts +2 -2
  107. package/dist/services/helper/Parser.js.map +1 -1
  108. package/dist/services/helper/extractors/Tweets.d.ts +6 -6
  109. package/dist/services/helper/extractors/Tweets.js +1 -1
  110. package/dist/services/helper/extractors/Tweets.js.map +1 -1
  111. package/dist/services/helper/extractors/Users.d.ts +4 -4
  112. package/dist/services/helper/extractors/Users.js +1 -1
  113. package/dist/services/helper/extractors/Users.js.map +1 -1
  114. package/dist/services/helper/payloads/LoginFlows.d.ts +77 -0
  115. package/dist/services/helper/payloads/LoginFlows.js +92 -0
  116. package/dist/services/helper/payloads/LoginFlows.js.map +1 -0
  117. package/dist/services/util/CacheService.d.ts +33 -0
  118. package/dist/services/util/CacheService.js +96 -0
  119. package/dist/services/util/CacheService.js.map +1 -0
  120. package/dist/services/util/FetcherService.d.ts +65 -0
  121. package/dist/services/util/FetcherService.js +214 -0
  122. package/dist/services/util/FetcherService.js.map +1 -0
  123. package/dist/types/Args.d.ts +38 -0
  124. package/dist/types/Args.js +5 -0
  125. package/dist/types/Args.js.map +1 -0
  126. package/dist/types/Authentication.d.ts +17 -2
  127. package/dist/types/Authentication.js +1 -0
  128. package/dist/types/Authentication.js.map +1 -1
  129. package/dist/types/Resolvers.d.ts +5 -4
  130. package/dist/types/Rettiwt.d.ts +16 -0
  131. package/dist/types/Rettiwt.js +3 -0
  132. package/dist/types/Rettiwt.js.map +1 -0
  133. package/dist/types/Service.d.ts +15 -23
  134. package/dist/types/Service.js +2 -16
  135. package/dist/types/Service.js.map +1 -1
  136. package/dist/types/Tweet.d.ts +25 -19
  137. package/dist/types/Tweet.js +0 -2
  138. package/dist/types/Tweet.js.map +1 -1
  139. package/dist/types/User.d.ts +35 -0
  140. package/dist/types/User.js +3 -0
  141. package/dist/types/User.js.map +1 -0
  142. package/dist/types/args/TweetFilter.d.ts +54 -0
  143. package/dist/types/args/TweetFilter.js +96 -0
  144. package/dist/types/args/TweetFilter.js.map +1 -0
  145. package/dist/types/args/TweetListArg.d.ts +10 -0
  146. package/dist/types/args/TweetListArg.js +42 -0
  147. package/dist/types/args/TweetListArg.js.map +1 -0
  148. package/dist/types/args/TweetListArgs.d.ts +20 -0
  149. package/dist/types/args/TweetListArgs.js +52 -0
  150. package/dist/types/args/TweetListArgs.js.map +1 -0
  151. package/dist/types/args/UserListArgs.d.ts +16 -0
  152. package/dist/types/args/UserListArgs.js +48 -0
  153. package/dist/types/args/UserListArgs.js.map +1 -0
  154. package/dist/types/data/Errors.d.ts +4 -1
  155. package/dist/types/data/Errors.js +3 -0
  156. package/dist/types/data/Errors.js.map +1 -1
  157. package/dist/types/data/TweetFilter.d.ts +49 -0
  158. package/dist/types/data/TweetFilter.js +63 -0
  159. package/dist/types/data/TweetFilter.js.map +1 -0
  160. package/dist/types/interfaces/Args.d.ts +38 -0
  161. package/dist/types/interfaces/Args.js +5 -0
  162. package/dist/types/interfaces/Args.js.map +1 -0
  163. package/dist/types/interfaces/Authentication.d.ts +40 -0
  164. package/dist/types/interfaces/Authentication.js +5 -0
  165. package/dist/types/interfaces/Authentication.js.map +1 -0
  166. package/dist/types/interfaces/Resolvers.d.ts +14 -0
  167. package/dist/types/interfaces/Resolvers.js +3 -0
  168. package/dist/types/interfaces/Resolvers.js.map +1 -0
  169. package/dist/types/interfaces/Rettiwt.d.ts +16 -0
  170. package/dist/types/interfaces/Rettiwt.js +3 -0
  171. package/dist/types/interfaces/Rettiwt.js.map +1 -0
  172. package/dist/types/interfaces/Service.d.ts +13 -0
  173. package/dist/types/interfaces/Service.js +3 -0
  174. package/dist/types/interfaces/Service.js.map +1 -0
  175. package/dist/types/interfaces/Services.d.ts +13 -0
  176. package/dist/types/interfaces/Services.js +3 -0
  177. package/dist/types/interfaces/Services.js.map +1 -0
  178. package/dist/types/interfaces/Tweet.d.ts +46 -0
  179. package/dist/types/interfaces/Tweet.js +3 -0
  180. package/dist/types/interfaces/Tweet.js.map +1 -0
  181. package/dist/types/interfaces/TweetFilter.d.ts +0 -0
  182. package/dist/types/interfaces/TweetFilter.js +2 -0
  183. package/dist/types/interfaces/TweetFilter.js.map +1 -0
  184. package/{src/types/data/User.ts → dist/types/interfaces/User.d.ts} +35 -51
  185. package/dist/types/interfaces/User.js +3 -0
  186. package/dist/types/interfaces/User.js.map +1 -0
  187. package/dist/types/raw/query/tweet/TweetDetails.d.ts +34 -0
  188. package/dist/types/raw/query/tweet/TweetDetails.js +5 -0
  189. package/dist/types/raw/query/tweet/TweetDetails.js.map +1 -0
  190. package/dist/types/raw/user/User.js.map +1 -1
  191. package/dist/types/services/args/TweetFilter.d.ts +50 -0
  192. package/dist/types/services/args/TweetFilter.js +76 -0
  193. package/dist/types/services/args/TweetFilter.js.map +1 -0
  194. package/docs/.nojekyll +1 -0
  195. package/docs/assets/highlight.css +64 -0
  196. package/docs/assets/main.js +58 -0
  197. package/docs/assets/search.js +1 -0
  198. package/docs/assets/style.css +1280 -0
  199. package/docs/classes/AccountService.html +303 -0
  200. package/docs/classes/AuthCookie.html +146 -0
  201. package/docs/classes/AuthService.html +147 -0
  202. package/docs/classes/CacheService.html +157 -0
  203. package/docs/classes/Cursor.html +102 -0
  204. package/docs/classes/CursoredData.html +126 -0
  205. package/docs/classes/DataValidationError.html +119 -0
  206. package/docs/classes/FetcherService.html +225 -0
  207. package/docs/classes/Tweet.html +210 -0
  208. package/docs/classes/TweetEntities.html +128 -0
  209. package/docs/classes/TweetFilter.html +204 -0
  210. package/docs/classes/TweetListArgs.html +118 -0
  211. package/docs/classes/TweetService.html +313 -0
  212. package/docs/classes/User.html +230 -0
  213. package/docs/classes/UserListArgs.html +118 -0
  214. package/docs/classes/UserService.html +315 -0
  215. package/docs/enums/HttpMethods.html +74 -0
  216. package/docs/functions/Rettiwt.html +99 -0
  217. package/docs/index.html +161 -0
  218. package/docs/interfaces/IAuthCookie.html +104 -0
  219. package/docs/interfaces/ICursor.html +77 -0
  220. package/docs/interfaces/ICursoredData.html +93 -0
  221. package/docs/interfaces/IDataContext.html +91 -0
  222. package/docs/interfaces/IListArgs.html +87 -0
  223. package/docs/interfaces/ITweet.html +176 -0
  224. package/docs/interfaces/ITweetEntities.html +104 -0
  225. package/docs/interfaces/ITweetFilter.html +158 -0
  226. package/docs/interfaces/IUser.html +194 -0
  227. package/docs/modules.html +109 -0
  228. package/package.json +5 -2
  229. package/src/enums/Errors.ts +21 -0
  230. package/src/graphql/enums/Errors.ts +21 -0
  231. package/src/graphql/queries/RootQuery.ts +11 -4
  232. package/src/graphql/resolvers/AccountResolver.ts +3 -3
  233. package/src/graphql/resolvers/ResolverBase.ts +19 -5
  234. package/src/graphql/resolvers/TweetResolver.ts +26 -17
  235. package/src/graphql/resolvers/UserResolver.ts +18 -20
  236. package/src/graphql/types/TweetTypes.ts +2 -2
  237. package/src/graphql/types/UserTypes.ts +1 -1
  238. package/src/index.ts +39 -17
  239. package/src/models/args/TweetFilter.ts +119 -0
  240. package/src/models/args/TweetListArgs.ts +47 -0
  241. package/src/models/args/UserListArgs.ts +47 -0
  242. package/src/models/auth/AuthCookie.ts +43 -0
  243. package/src/models/data/CursoredData.ts +45 -0
  244. package/src/models/data/Tweet.ts +118 -0
  245. package/src/models/data/User.ts +72 -0
  246. package/src/models/errors/DataValidationError.ts +29 -0
  247. package/src/server.ts +9 -10
  248. package/src/services/{accounts → auth}/AccountService.ts +92 -17
  249. package/src/services/auth/AuthService.ts +81 -0
  250. package/src/services/data/TweetService.ts +77 -58
  251. package/src/services/data/UserService.ts +93 -89
  252. package/src/services/helper/Headers.ts +4 -4
  253. package/src/services/helper/Parser.ts +2 -2
  254. package/src/services/helper/extractors/Tweets.ts +7 -7
  255. package/src/services/helper/extractors/Users.ts +5 -5
  256. package/src/services/{CacheService.ts → util/CacheService.ts} +4 -1
  257. package/src/services/{FetcherService.ts → util/FetcherService.ts} +19 -11
  258. package/src/types/Args.ts +49 -0
  259. package/src/types/Authentication.ts +29 -7
  260. package/src/types/Resolvers.ts +5 -4
  261. package/src/types/Rettiwt.ts +20 -0
  262. package/src/types/Service.ts +24 -0
  263. package/src/types/Tweet.ts +61 -0
  264. package/src/types/User.ts +48 -0
  265. package/tsconfig.json +2 -2
  266. package/src/services/AuthService.ts +0 -68
  267. package/src/services/helper/deserializers/Tweets.ts +0 -70
  268. package/src/services/helper/deserializers/Users.ts +0 -26
  269. package/src/types/data/Errors.ts +0 -34
  270. package/src/types/data/Service.ts +0 -55
  271. package/src/types/data/Tweet.ts +0 -123
  272. package/src/types/raw/auth/Cookie.ts +0 -16
  273. /package/src/{types → enums}/HTTP.ts +0 -0
  274. /package/src/services/{accounts → helper/payloads}/LoginFlows.ts +0 -0
@@ -1,6 +1,6 @@
1
1
  // TYPES
2
- import { DataExtract } from '../../../types/Resolvers'
3
- import { DataErrors } from '../../../types/data/Errors';
2
+ import { IDataExtract } from '../../../types/Resolvers'
3
+ import { DataErrors } from '../../../enums/Errors';
4
4
  import RawUser from '../../../types/raw/user/User';
5
5
  import RawUserFollowers from '../../../types/raw/user/Followers';
6
6
  import RawUserFollowing from '../../../types/raw/user/Following';
@@ -13,7 +13,7 @@ import * as Parsers from '../Parser';
13
13
  * @returns The raw user account data formatted and sorted into required and additional data
14
14
  * @param res The raw response received from Twitter
15
15
  */
16
- export function extractUserDetails(res: RawUser): DataExtract {
16
+ export function extractUserDetails(res: RawUser): IDataExtract {
17
17
  let required: any[] = []; // To store the reqruied raw data
18
18
  let cursor: string = ''; // To store the cursor to next batch
19
19
  let users: any[] = []; // To store additional user data
@@ -41,7 +41,7 @@ export function extractUserDetails(res: RawUser): DataExtract {
41
41
  * @returns The raw user following/followers data formatted and sorted into required and additional data
42
42
  * @param res The raw response received from TwitterAPI
43
43
  */
44
- export function extractUserFollow(res: RawUserFollowers | RawUserFollowing): DataExtract {
44
+ export function extractUserFollow(res: RawUserFollowers | RawUserFollowing): IDataExtract {
45
45
  let required: any[] = []; // To store the reqruied raw data
46
46
  let cursor: string = ''; // To store the cursor to next batch
47
47
  let users: any[] = []; // To store additional user data
@@ -94,7 +94,7 @@ export function extractUserFollow(res: RawUserFollowers | RawUserFollowing): Dat
94
94
  * @returns The raw user likes data formatted and sorted into required and additional data
95
95
  * @param res The raw response received from TwitterAPI
96
96
  */
97
- export function extractUserLikes(res: RawUserLikes): DataExtract {
97
+ export function extractUserLikes(res: RawUserLikes): IDataExtract {
98
98
  let required: any[] = []; // To store the reqruied raw data
99
99
  let cursor: string = ''; // To store the cursor to next batch
100
100
  let users: any[] = []; // To store additional user data
@@ -2,7 +2,7 @@
2
2
  import NodeCache from 'node-cache';
3
3
 
4
4
  // PARSERS
5
- import * as Parsers from './helper/Parser';
5
+ import * as Parsers from '../helper/Parser';
6
6
 
7
7
  /**
8
8
  * Handles reading and writing of data from and to cache.
@@ -40,7 +40,9 @@ export class CacheService {
40
40
  * Stores the input data in the cache.
41
41
  *
42
42
  * @param data The input data to store.
43
+ *
43
44
  * @returns Whether writing to cache was successful or not.
45
+ *
44
46
  * @remarks In order to cache data, the data to be cached must have a unique 'id' field.
45
47
  */
46
48
  public write(data: any): void {
@@ -62,6 +64,7 @@ export class CacheService {
62
64
 
63
65
  /**
64
66
  * @param id The id id of the data to be fetched from cache.
67
+ *
65
68
  * @returns The data with the given id.
66
69
  */
67
70
  public read(id: string): any {
@@ -2,18 +2,22 @@
2
2
  import { curly, CurlyResult } from 'node-libcurl';
3
3
 
4
4
  // SERVICES
5
- import { AuthService } from './AuthService';
5
+ import { AuthService } from '../auth/AuthService';
6
6
  import { CacheService } from './CacheService';
7
7
 
8
+ // MODELS
9
+ import { Tweet } from '../../models/data/Tweet';
10
+ import { User } from '../../models/data/User';
11
+
8
12
  // TYPES
9
- import { HttpStatus } from "../types/HTTP";
10
- import { Result as RawUser } from '../types/raw/user/User';
11
- import { Result as RawTweet } from '../types/raw/tweet/Tweet';
13
+ import { Result as RawUser } from '../../types/raw/user/User';
14
+ import { Result as RawTweet } from '../../types/raw/tweet/Tweet';
15
+
16
+ // ENUMS
17
+ import { HttpStatus } from "../../enums/HTTP";
12
18
 
13
19
  // HELPERS
14
- import * as Headers from './helper/Headers'
15
- import * as UserDeserializers from './helper/deserializers/Users';
16
- import * as TweetDeserializers from './helper/deserializers/Tweets';
20
+ import * as Headers from '../helper/Headers'
17
21
  import { CurlyOptions } from 'node-libcurl/dist/curly';
18
22
 
19
23
  /**
@@ -55,8 +59,10 @@ export class FetcherService {
55
59
  * The middleware for handling any HTTP error.
56
60
  *
57
61
  * @param res The response object received.
58
- * @throws {@link HttpStatus}.
62
+ *
59
63
  * @returns The received response, if no HTTP errors are found.
64
+ *
65
+ * @throws {@link HttpStatus} error, if any HTTP error is found.
60
66
  */
61
67
  private handleHTTPError(res: CurlyResult): CurlyResult {
62
68
  /**
@@ -79,6 +85,7 @@ export class FetcherService {
79
85
  * @param authenticate Whether to authenticate requests or not.
80
86
  * @param method The HTTP method (from {@link HttpMethods}) to use.
81
87
  * @param data The data to be sent along with the request (for POST request).
88
+ *
82
89
  * @returns The {@link CurlyResult} received.
83
90
  */
84
91
  protected async request<DataType>(url: string, authenticate: boolean = true, method: HttpMethods = HttpMethods.GET, data?: any): Promise<CurlyResult<DataType>> {
@@ -114,15 +121,15 @@ export class FetcherService {
114
121
  /**
115
122
  * Caches the extracted data into the {@link CacheService} instance.
116
123
  *
117
- * @param data The extracted data to be cached
124
+ * @param data The extracted data to be cached.
118
125
  */
119
126
  protected cacheData(data: any): void {
120
127
  /**
121
128
  * The extracted data is in raw form.
122
129
  * This raw data is deserialized into the respective known types.
123
130
  */
124
- let users = data.users.map((user: RawUser) => UserDeserializers.toUser(user));
125
- let tweets = data.tweets.map((tweet: RawTweet) => TweetDeserializers.toTweet(tweet));
131
+ let users = data.users.map((user: RawUser) => new User(user));
132
+ let tweets = data.tweets.map((tweet: RawTweet) => new Tweet(tweet));
126
133
 
127
134
  // Caching the data
128
135
  this.cache.write(users);
@@ -133,6 +140,7 @@ export class FetcherService {
133
140
  * Fetches the data with the given id from the cache.
134
141
  *
135
142
  * @param id The id of the data to be read from cache.
143
+ *
136
144
  * @returns The data with the given id. If does not exists, returns undefined.
137
145
  */
138
146
  protected readData(id: string): any {
@@ -0,0 +1,49 @@
1
+ /**
2
+ * The filter to be used for fetching tweets from Twitter.
3
+ *
4
+ * @public
5
+ */
6
+ export interface ITweetFilter {
7
+ /** The list of words to search. */
8
+ words?: string[];
9
+
10
+ /** The list of hashtags to search. */
11
+ hashtags?: string[];
12
+
13
+ /** The list of usernames whose tweets are to be searched. */
14
+ fromUsers?: string[];
15
+
16
+ /** The list of username to whom the tweets to be searched, are adressed. */
17
+ toUsers?: string[];
18
+
19
+ /** The list of username mentioned in the tweets to search. */
20
+ mentions?: string[];
21
+
22
+ /** The date starting from which tweets are to be searched. */
23
+ startDate?: string;
24
+
25
+ /** The date upto which tweets are to be searched. */
26
+ endDate?: string;
27
+
28
+ /** The id of the tweet, after which the tweets are to be searched. */
29
+ sinceId?: string;
30
+
31
+ /** The id of the tweet which is quoted in the tweets to search. */
32
+ quoted?: string;
33
+
34
+ /** Whether to fetch tweets that are links or not. */
35
+ links?: boolean;
36
+ };
37
+
38
+ /**
39
+ * The arguments for fetching cursored list.
40
+ *
41
+ * @public
42
+ */
43
+ export interface IListArgs {
44
+ /** The number of data items to fetch. */
45
+ count?: number;
46
+
47
+ /** The cursor to the batch of data to fetch. */
48
+ cursor?: string;
49
+ };
@@ -3,17 +3,18 @@
3
3
  *
4
4
  * @internal
5
5
  */
6
- export interface GuestCredentials {
6
+ export interface IGuestCredentials {
7
7
  /** The bearer token from twitter.com.
8
8
  *
9
9
  * @remarks This is a static bearer token from twitter.com.
10
10
  */
11
- authToken: string,
11
+ authToken: string;
12
+
12
13
  /** The guest token.
13
14
  *
14
15
  * @remarks This is generated from twitter.com by calling GETTING https://api.twitter.com/1.1/guest/activate.json endpoint.
15
16
  */
16
- guestToken: string
17
+ guestToken: string;
17
18
  };
18
19
 
19
20
  /**
@@ -21,21 +22,42 @@ export interface GuestCredentials {
21
22
  *
22
23
  * @internal
23
24
  */
24
- export interface AuthCredentials {
25
+ export interface IAuthCredentials {
25
26
  /** The bearer token from twitter.com.
26
27
  *
27
28
  * @remarks This is a static bearer token from twitter.com.
28
29
  */
29
- authToken: string,
30
+ authToken: string;
31
+
30
32
  /** The guest token.
31
33
  *
32
34
  * @remarks This is generated from twitter.com by calling GETTING https://api.twitter.com/1.1/guest/activate.json endpoint.
33
35
  */
34
- csrfToken: string,
36
+ csrfToken: string;
37
+
35
38
  /** The cookie of the twitter account, which is used to authenticate against twitter.
36
39
  *
37
40
  * @remarks The cookie can be obtained/scraped from any one of the outgoing HTTP request headers to twitter.com.
38
41
  * It can also be obtained after logging in to twitter, from the 'set-cookie' field of response.
39
42
  */
40
- cookie: string
43
+ cookie: string;
44
+ };
45
+
46
+ /**
47
+ * The cookie containing the tokens that are used to authenticate against Twitter.
48
+ *
49
+ * @public
50
+ */
51
+ export interface IAuthCookie {
52
+ /** Token used to authenticate a device. */
53
+ kdt: string;
54
+
55
+ /** Token used to authenticate a user using a Twitter ID. */
56
+ twid: string;
57
+
58
+ /** The CSRF token of the session. */
59
+ ct0: string;
60
+
61
+ /** The authentication token used while logging in to the account. */
62
+ auth_token: string;
41
63
  };
@@ -1,17 +1,18 @@
1
1
  /**
2
2
  * The data returned from extractor methods.
3
+ *
3
4
  * @internal
4
5
  */
5
- export interface DataExtract {
6
+ export interface IDataExtract {
6
7
  /** The required data. */
7
- required: any;
8
+ required: any[];
8
9
 
9
10
  /** The cursor string to the next batch of data. */
10
11
  cursor: string;
11
12
 
12
13
  /** Additional extracted user details. */
13
- users: any;
14
+ users: any[];
14
15
 
15
16
  /** Additional extracted tweet details */
16
- tweets: any;
17
+ tweets: any[];
17
18
  }
@@ -0,0 +1,20 @@
1
+ // SERVICES
2
+ import { AccountService } from "../services/auth/AccountService";
3
+ import { TweetService } from "../services/data/TweetService";
4
+ import { UserService } from "../services/data/UserService";
5
+
6
+ /**
7
+ * The data context from where data is to be fetched.
8
+ *
9
+ * @public
10
+ */
11
+ export interface IDataContext {
12
+ /** Handles data related to users. */
13
+ users: UserService,
14
+
15
+ /** Handles data related to tweets. */
16
+ tweets: TweetService,
17
+
18
+ /** Handles account related operations. */
19
+ account: AccountService
20
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The cursor to the batch of data to be fetched.
3
+ *
4
+ * @public
5
+ */
6
+ export interface ICursor {
7
+ /** The cursor string. */
8
+ value: string;
9
+ };
10
+
11
+ /**
12
+ * The data that us fetched batch-wise along with a cursor.
13
+ *
14
+ * @typeParam Type - The type of data present in the list.
15
+ *
16
+ * @public
17
+ */
18
+ export interface ICursoredData<Type> {
19
+ /** The list of data of the given type. */
20
+ list: Type[];
21
+
22
+ /** The cursor to the next batch of data. */
23
+ next: ICursor;
24
+ };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The different types parsed entities like urls, media, mentions, hashtags, etc.
3
+ *
4
+ * @public
5
+ */
6
+ export interface ITweetEntities {
7
+ /** The list of hashtags mentioned in the tweet. */
8
+ hashtags: string[];
9
+
10
+ /** The list of urls mentioned in the tweet. */
11
+ urls: string[];
12
+
13
+ /** The list of IDs of users mentioned in the tweet. */
14
+ mentionedUsers: string[];
15
+
16
+ /** The list of urls to various media mentioned in the tweet. */
17
+ media: string[];
18
+ }
19
+
20
+ /**
21
+ * The details of a single Tweet.
22
+ *
23
+ * @public
24
+ */
25
+ export interface ITweet {
26
+ /** The rest id of the tweet. */
27
+ id: string;
28
+
29
+ /** The rest id of the user who made the tweet. */
30
+ tweetBy: string;
31
+
32
+ /** The date and time of creation of the tweet, in UTC string format. */
33
+ createdAt: string;
34
+
35
+ /** Additional tweet entities like urls, mentions, etc. */
36
+ entities: ITweetEntities;
37
+
38
+ /** The rest id of the tweet which is quoted in the tweet. */
39
+ quoted: string;
40
+
41
+ /** The full text content of the tweet. */
42
+ fullText: string;
43
+
44
+ /** The rest id of the user to which the tweet is a reply. */
45
+ replyTo: string;
46
+
47
+ /** The language in which the tweet is written. */
48
+ lang: string;
49
+
50
+ /** The number of quotes of the tweet. */
51
+ quoteCount: number;
52
+
53
+ /** The number of replies to the tweet. */
54
+ replyCount: number;
55
+
56
+ /** The number of retweets of the tweet. */
57
+ retweetCount: number;
58
+
59
+ /** The number of likes of the tweet. */
60
+ likeCount: number;
61
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The details of a single user.
3
+ *
4
+ * @public
5
+ */
6
+ export interface IUser {
7
+ /** The rest id of the user. */
8
+ id: string;
9
+
10
+ /** The username/screenname of the user. */
11
+ userName: string;
12
+
13
+ /** The full name of the user. */
14
+ fullName: string;
15
+
16
+ /** The creation date of user's account. */
17
+ createdAt: string;
18
+
19
+ /** The user's description. */
20
+ description: string;
21
+
22
+ /** Whether the account is verified or not. */
23
+ isVerified: boolean;
24
+
25
+ /** The number of tweets liked by the user. */
26
+ favouritesCount: number;
27
+
28
+ /** The number of followers of the user. */
29
+ followersCount: number;
30
+
31
+ /** The number of following of the user. */
32
+ followingsCount: number;
33
+
34
+ /** The number of tweets made by the user. */
35
+ statusesCount: number;
36
+
37
+ /** The location of user as provided by user. */
38
+ location: string;
39
+
40
+ /** The rest id of the tweet pinned in the user's profile. */
41
+ pinnedTweet: string;
42
+
43
+ /** The url of the profile banner image. */
44
+ profileBanner: string;
45
+
46
+ /** The url of the profile image. */
47
+ profileImage: string;
48
+ }
package/tsconfig.json CHANGED
@@ -12,8 +12,8 @@
12
12
  // "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
13
13
  // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
14
14
  // "jsx": "preserve", /* Specify what JSX code is generated. */
15
- // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
16
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
15
+ "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
16
+ "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
17
17
  // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
18
18
  // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
19
19
  // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
@@ -1,68 +0,0 @@
1
- // PACKAGE
2
- import axios from 'axios';
3
-
4
- // URLS
5
- import { guestTokenUrl } from './helper/urls/Authentication';
6
-
7
- // TYPES
8
- import { GuestCredentials, AuthCredentials } from '../types/Authentication';
9
-
10
- // CONFIGS
11
- import { config } from '../config/env';
12
-
13
- /**
14
- * Handles authentication of http requests and other authentication related tasks.
15
- * @internal
16
- */
17
- export class AuthService {
18
- // MEMBER DATA
19
- /** The common bearer token for authentication. */
20
- private authToken: string;
21
-
22
- /** The current authentication credentials. */
23
- private credentials: AuthCredentials;
24
-
25
- /** Whether instance has been authenticated or not. */
26
- public isAuthenticated: boolean;
27
-
28
- // MEMBER METHODS
29
- constructor(cookie: string = '') {
30
- // Reading the auth token from the config, since it's always the same
31
- this.authToken = config.twitter_auth_token;
32
-
33
- // Setting authentication status
34
- this.isAuthenticated = cookie != '';
35
-
36
- // Setting up the authenticated credentials
37
- /**
38
- * The following regex pattern is used to extract the csrfToken from the cookie string.
39
- * This is done by matching any string between the characters 'ct0=' and nearest enclosing ';'.
40
- * (?<=pattern) starts matching after the given pattern.
41
- * (?=pattern) stops matching just before the pattern.
42
- */
43
- this.credentials = { authToken: this.authToken, csrfToken: cookie.match(/(?<=ct0=).+?(?=;)/) + '', cookie: cookie};
44
-
45
- }
46
-
47
- /**
48
- * @returns The current authentication credentials. A different credential is returned each time this is invoked
49
- */
50
- async getAuthCredentials(): Promise<AuthCredentials> {
51
- return this.credentials;
52
- }
53
-
54
- /**
55
- * @returns The guest credentials fetched from twitter.
56
- */
57
- async getGuestCredentials(): Promise<GuestCredentials> {
58
- // Getting the guest credentials from twitter
59
- return await axios.post<{ guest_token: string }>(guestTokenUrl(), null, {
60
- headers: {
61
- 'Authorization': this.authToken
62
- }
63
- }).then(res => ({
64
- authToken: this.authToken,
65
- guestToken: res.data.guest_token
66
- }));
67
- }
68
- }
@@ -1,70 +0,0 @@
1
- // TYPES
2
- import { Tweet, TweetEntities } from '../../../types/data/Tweet';
3
- import { Result as RawTweet, Entities2 as RawTweetEntities } from '../../../types/raw/tweet/Tweet';
4
-
5
- // PARSERS
6
- import * as Parsers from '../Parser';
7
-
8
- /**
9
- * @returns A TweetEntities object containing the various tweet entities
10
- * @param data The raw tweet entities data from the response received from TwitterAPI
11
- */
12
- export function toTweetEntities(data: RawTweetEntities): TweetEntities {
13
- let entities: TweetEntities = {
14
- mentionedUsers: [],
15
- urls: [],
16
- media: [],
17
- hashtags: []
18
- };
19
-
20
- // Extracting user mentions
21
- if(data.user_mentions) {
22
- for(let user of data.user_mentions) {
23
- entities.mentionedUsers.push(user.id_str);
24
- }
25
- }
26
-
27
- // Extracting urls
28
- if(data.urls) {
29
- for(let url of data.urls) {
30
- entities.urls.push(url.expanded_url);
31
- }
32
- }
33
-
34
- // Extracting hashtags
35
- if(data.hashtags) {
36
- for(let hashtag of data.hashtags) {
37
- entities.hashtags.push(hashtag.text);
38
- }
39
- }
40
-
41
- // Extracting media urls (if any)
42
- if(data.media) {
43
- for(const media of data.media) {
44
- entities.media.push(media.media_url_https);
45
- }
46
- }
47
-
48
- return entities;
49
- }
50
-
51
- /**
52
- * @returns A Tweet object containing the tweet data
53
- * @param data The raw tweet data from the response received from TwitterAPI
54
- */
55
- export function toTweet(data: RawTweet): Tweet {
56
- return {
57
- id: data.rest_id,
58
- createdAt: data.legacy.created_at,
59
- tweetBy: data.legacy.user_id_str,
60
- entities: toTweetEntities(data.legacy.entities),
61
- quoted: data.legacy.quoted_status_id_str,
62
- fullText: Parsers.normalizeText(data.legacy.full_text),
63
- replyTo: data.legacy.in_reply_to_status_id_str,
64
- lang: data.legacy.lang,
65
- quoteCount: data.legacy.quote_count,
66
- replyCount: data.legacy.reply_count,
67
- retweetCount: data.legacy.retweet_count,
68
- likeCount: data.legacy.favorite_count
69
- };
70
- }
@@ -1,26 +0,0 @@
1
- // TYPES
2
- import { User } from '../../../types/data/User';
3
- import { Result as RawUser } from '../../../types/raw/user/User';
4
-
5
- /**
6
- * @returns A User object containing the user details
7
- * @param data The raw user data from Twitter API
8
- */
9
- export function toUser(data: RawUser): User {
10
- return {
11
- id: data.rest_id,
12
- userName: data.legacy.screen_name,
13
- fullName: data.legacy.name,
14
- createdAt: data.legacy.created_at,
15
- description: data.legacy.description,
16
- isVerified: data.legacy.verified,
17
- favouritesCount: data.legacy.favourites_count,
18
- followersCount: data.legacy.followers_count,
19
- followingsCount: data.legacy.friends_count,
20
- statusesCount: data.legacy.statuses_count,
21
- location: data.legacy.location,
22
- pinnedTweet: data.legacy.pinned_tweet_ids_str[0],
23
- profileBanner: data.legacy.profile_banner_url,
24
- profileImage: data.legacy.profile_image_url_https
25
- };
26
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * Different types of error messages related to authentication.
3
- *
4
- * @public
5
- */
6
- export enum AuthenticationErrors {
7
- NotAuthenticated = "Cannot fetch this data without authentication",
8
- };
9
-
10
- /**
11
- * Different types error messages for validation errors.
12
- *
13
- * @public
14
- */
15
- export enum ValidationErrors {
16
- InvalidTweetFilter = "Atleast one of fromUsers/toUsers/mentions/hashtags/words argument is required",
17
- NoUserIdentification = "Either userName or id must be given",
18
- InvalidCount = "Invalid count provided"
19
- };
20
-
21
- /**
22
- * Different type of error messages that are returned by services.
23
- *
24
- * @public
25
- */
26
- export enum DataErrors {
27
- UserNotFound = "An account with given username/id was not found",
28
- TweetNotFound = "A tweet with the given id was not found",
29
- NoTweetsFound = "No tweets matching the given criteria found",
30
- NoLikersFound = "No likers found for the tweet with the given id",
31
- NoRetweetersFound = "No retweeters found for the tweet with the given id",
32
- NoFollowsFound = "No follow details were found for the user with the given id",
33
- NoLikedTweetsFound = "No liked tweets were found for the user with the given id"
34
- };