rettiwt-api 1.1.2 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) 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 +21 -0
  18. package/dist/graphql/enums/Errors.js +29 -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 +13 -4
  31. package/dist/graphql/resolvers/UserResolver.js +83 -18
  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/graphql/types/UserTypes.js +1 -1
  39. package/dist/graphql/types/UserTypes.js.map +1 -1
  40. package/dist/index.d.ts +31 -15
  41. package/dist/index.js +32 -17
  42. package/dist/index.js.map +1 -1
  43. package/dist/middlewares/Authentication.d.ts +0 -0
  44. package/dist/middlewares/Authentication.js +2 -0
  45. package/dist/middlewares/Authentication.js.map +1 -0
  46. package/dist/models/args/TweetFilter.d.ts +59 -0
  47. package/dist/models/args/TweetFilter.js +101 -0
  48. package/dist/models/args/TweetFilter.js.map +1 -0
  49. package/dist/models/args/TweetListArgs.d.ts +21 -0
  50. package/dist/models/args/TweetListArgs.js +54 -0
  51. package/dist/models/args/TweetListArgs.js.map +1 -0
  52. package/dist/models/args/UserListArgs.d.ts +21 -0
  53. package/dist/models/args/UserListArgs.js +54 -0
  54. package/dist/models/args/UserListArgs.js.map +1 -0
  55. package/dist/models/auth/AuthCookie.d.ts +21 -0
  56. package/dist/models/auth/AuthCookie.js +33 -0
  57. package/dist/models/auth/AuthCookie.js.map +1 -0
  58. package/dist/models/data/CursoredData.d.ts +34 -0
  59. package/dist/models/data/CursoredData.js +42 -0
  60. package/dist/models/data/CursoredData.js.map +1 -0
  61. package/dist/models/data/DataValidationError.d.ts +18 -0
  62. package/dist/models/data/DataValidationError.js +21 -0
  63. package/dist/models/data/DataValidationError.js.map +1 -0
  64. package/dist/models/data/Errors.d.ts +18 -0
  65. package/dist/models/data/Errors.js +21 -0
  66. package/dist/models/data/Errors.js.map +1 -0
  67. package/dist/models/data/Service.d.ts +33 -0
  68. package/dist/models/data/Service.js +41 -0
  69. package/dist/models/data/Service.js.map +1 -0
  70. package/dist/models/data/Tweet.d.ts +53 -0
  71. package/dist/models/data/Tweet.js +104 -0
  72. package/dist/models/data/Tweet.js.map +1 -0
  73. package/dist/models/data/User.d.ts +41 -0
  74. package/dist/models/data/User.js +32 -0
  75. package/dist/models/data/User.js.map +1 -0
  76. package/dist/models/errors/DataValidationError.d.ts +20 -0
  77. package/dist/models/errors/DataValidationError.js +23 -0
  78. package/dist/models/errors/DataValidationError.js.map +1 -0
  79. package/dist/models/query/Variables.d.ts +2 -0
  80. package/dist/models/query/Variables.js +10 -0
  81. package/dist/models/query/Variables.js.map +1 -0
  82. package/dist/requests/Url.d.ts +5 -0
  83. package/dist/requests/Url.js +12 -0
  84. package/dist/requests/Url.js.map +1 -0
  85. package/dist/requests/payloads/Variables.d.ts +23 -0
  86. package/dist/requests/payloads/Variables.js +24 -0
  87. package/dist/requests/payloads/Variables.js.map +1 -0
  88. package/dist/server.d.ts +1 -1
  89. package/dist/server.js +9 -10
  90. package/dist/server.js.map +1 -1
  91. package/dist/services/accounts/AccountService.d.ts +6 -0
  92. package/dist/services/accounts/AccountService.js +6 -0
  93. package/dist/services/accounts/AccountService.js.map +1 -1
  94. package/dist/services/auth/AccountService.d.ts +88 -0
  95. package/dist/services/auth/AccountService.js +392 -0
  96. package/dist/services/auth/AccountService.js.map +1 -0
  97. package/dist/services/auth/AuthService.d.ts +31 -0
  98. package/dist/services/auth/AuthService.js +118 -0
  99. package/dist/services/auth/AuthService.js.map +1 -0
  100. package/dist/services/auth/LoginFlows.d.ts +77 -0
  101. package/dist/services/auth/LoginFlows.js +92 -0
  102. package/dist/services/auth/LoginFlows.js.map +1 -0
  103. package/dist/services/data/TweetService.d.ts +46 -16
  104. package/dist/services/data/TweetService.js +71 -54
  105. package/dist/services/data/TweetService.js.map +1 -1
  106. package/dist/services/data/UserService.d.ts +58 -19
  107. package/dist/services/data/UserService.js +104 -68
  108. package/dist/services/data/UserService.js.map +1 -1
  109. package/dist/services/helper/Headers.d.ts +4 -4
  110. package/dist/services/helper/Headers.js.map +1 -1
  111. package/dist/services/helper/Parser.d.ts +2 -2
  112. package/dist/services/helper/Parser.js.map +1 -1
  113. package/dist/services/helper/extractors/Tweets.d.ts +6 -6
  114. package/dist/services/helper/extractors/Tweets.js +1 -1
  115. package/dist/services/helper/extractors/Tweets.js.map +1 -1
  116. package/dist/services/helper/extractors/Users.d.ts +10 -4
  117. package/dist/services/helper/extractors/Users.js +54 -2
  118. package/dist/services/helper/extractors/Users.js.map +1 -1
  119. package/dist/services/helper/payloads/LoginFlows.d.ts +77 -0
  120. package/dist/services/helper/payloads/LoginFlows.js +92 -0
  121. package/dist/services/helper/payloads/LoginFlows.js.map +1 -0
  122. package/dist/services/helper/urls/Users.d.ts +8 -1
  123. package/dist/services/helper/urls/Users.js +12 -2
  124. package/dist/services/helper/urls/Users.js.map +1 -1
  125. package/dist/services/util/CacheService.d.ts +33 -0
  126. package/dist/services/util/CacheService.js +96 -0
  127. package/dist/services/util/CacheService.js.map +1 -0
  128. package/dist/services/util/FetcherService.d.ts +65 -0
  129. package/dist/services/util/FetcherService.js +214 -0
  130. package/dist/services/util/FetcherService.js.map +1 -0
  131. package/dist/types/Args.d.ts +38 -0
  132. package/dist/types/Args.js +5 -0
  133. package/dist/types/Args.js.map +1 -0
  134. package/dist/types/Authentication.d.ts +17 -2
  135. package/dist/types/Authentication.js +1 -0
  136. package/dist/types/Authentication.js.map +1 -1
  137. package/dist/types/Query.d.ts +80 -0
  138. package/dist/types/Query.js +3 -0
  139. package/dist/types/Query.js.map +1 -0
  140. package/dist/types/Resolvers.d.ts +5 -4
  141. package/dist/types/Rettiwt.d.ts +16 -0
  142. package/dist/types/Rettiwt.js +3 -0
  143. package/dist/types/Rettiwt.js.map +1 -0
  144. package/dist/types/Service.d.ts +15 -23
  145. package/dist/types/Service.js +2 -16
  146. package/dist/types/Service.js.map +1 -1
  147. package/dist/types/Tweet.d.ts +25 -19
  148. package/dist/types/Tweet.js +0 -2
  149. package/dist/types/Tweet.js.map +1 -1
  150. package/dist/types/User.d.ts +35 -0
  151. package/dist/types/User.js +3 -0
  152. package/dist/types/User.js.map +1 -0
  153. package/dist/types/args/TweetFilter.d.ts +54 -0
  154. package/dist/types/args/TweetFilter.js +96 -0
  155. package/dist/types/args/TweetFilter.js.map +1 -0
  156. package/dist/types/args/TweetListArg.d.ts +10 -0
  157. package/dist/types/args/TweetListArg.js +42 -0
  158. package/dist/types/args/TweetListArg.js.map +1 -0
  159. package/dist/types/args/TweetListArgs.d.ts +20 -0
  160. package/dist/types/args/TweetListArgs.js +52 -0
  161. package/dist/types/args/TweetListArgs.js.map +1 -0
  162. package/dist/types/args/UserListArgs.d.ts +16 -0
  163. package/dist/types/args/UserListArgs.js +48 -0
  164. package/dist/types/args/UserListArgs.js.map +1 -0
  165. package/dist/types/data/TweetFilter.d.ts +49 -0
  166. package/dist/types/data/TweetFilter.js +63 -0
  167. package/dist/types/data/TweetFilter.js.map +1 -0
  168. package/dist/types/interfaces/Args.d.ts +38 -0
  169. package/dist/types/interfaces/Args.js +5 -0
  170. package/dist/types/interfaces/Args.js.map +1 -0
  171. package/dist/types/interfaces/Authentication.d.ts +40 -0
  172. package/dist/types/interfaces/Authentication.js +5 -0
  173. package/dist/types/interfaces/Authentication.js.map +1 -0
  174. package/dist/types/interfaces/Resolvers.d.ts +14 -0
  175. package/dist/types/interfaces/Resolvers.js +3 -0
  176. package/dist/types/interfaces/Resolvers.js.map +1 -0
  177. package/dist/types/interfaces/Rettiwt.d.ts +16 -0
  178. package/dist/types/interfaces/Rettiwt.js +3 -0
  179. package/dist/types/interfaces/Rettiwt.js.map +1 -0
  180. package/dist/types/interfaces/Service.d.ts +13 -0
  181. package/dist/types/interfaces/Service.js +3 -0
  182. package/dist/types/interfaces/Service.js.map +1 -0
  183. package/dist/types/interfaces/Services.d.ts +13 -0
  184. package/dist/types/interfaces/Services.js +3 -0
  185. package/dist/types/interfaces/Services.js.map +1 -0
  186. package/dist/types/interfaces/Tweet.d.ts +46 -0
  187. package/dist/types/interfaces/Tweet.js +3 -0
  188. package/dist/types/interfaces/Tweet.js.map +1 -0
  189. package/dist/types/interfaces/TweetFilter.d.ts +0 -0
  190. package/dist/types/interfaces/TweetFilter.js +2 -0
  191. package/dist/types/interfaces/TweetFilter.js.map +1 -0
  192. package/{src/types/data/User.ts → dist/types/interfaces/User.d.ts} +35 -51
  193. package/dist/types/interfaces/User.js +3 -0
  194. package/dist/types/interfaces/User.js.map +1 -0
  195. package/dist/types/raw/data/tweet/Favouriters.d.ts +164 -0
  196. package/dist/types/raw/data/tweet/Favouriters.js +3 -0
  197. package/dist/types/raw/data/tweet/Favouriters.js.map +1 -0
  198. package/dist/types/raw/data/tweet/Retweeters.d.ts +171 -0
  199. package/dist/types/raw/data/tweet/Retweeters.js +3 -0
  200. package/dist/types/raw/data/tweet/Retweeters.js.map +1 -0
  201. package/dist/types/raw/data/tweet/Tweet.d.ts +746 -0
  202. package/dist/types/raw/data/tweet/Tweet.js +3 -0
  203. package/dist/types/raw/data/tweet/Tweet.js.map +1 -0
  204. package/dist/types/raw/data/tweet/Tweets.d.ts +386 -0
  205. package/dist/types/raw/data/tweet/Tweets.js +3 -0
  206. package/dist/types/raw/data/tweet/Tweets.js.map +1 -0
  207. package/dist/types/raw/data/user/Followers.d.ts +176 -0
  208. package/dist/types/raw/data/user/Followers.js +3 -0
  209. package/dist/types/raw/data/user/Followers.js.map +1 -0
  210. package/dist/types/raw/data/user/Following.d.ts +176 -0
  211. package/dist/types/raw/data/user/Following.js +3 -0
  212. package/dist/types/raw/data/user/Following.js.map +1 -0
  213. package/dist/types/raw/data/user/Likes.d.ts +1059 -0
  214. package/dist/types/raw/data/user/Likes.js +3 -0
  215. package/dist/types/raw/data/user/Likes.js.map +1 -0
  216. package/dist/types/raw/data/user/User.d.ts +117 -0
  217. package/dist/types/raw/data/user/User.js +3 -0
  218. package/dist/types/raw/data/user/User.js.map +1 -0
  219. package/dist/types/raw/query/tweet/Details.d.ts +80 -0
  220. package/dist/types/raw/query/tweet/Details.js +5 -0
  221. package/dist/types/raw/query/tweet/Details.js.map +1 -0
  222. package/dist/types/raw/query/tweet/Engagements.d.ts +29 -0
  223. package/dist/types/raw/query/tweet/Engagements.js +3 -0
  224. package/dist/types/raw/query/tweet/Engagements.js.map +1 -0
  225. package/dist/types/raw/query/tweet/Likes.d.ts +29 -0
  226. package/dist/types/raw/query/tweet/Likes.js +3 -0
  227. package/dist/types/raw/query/tweet/Likes.js.map +1 -0
  228. package/dist/types/raw/query/tweet/Retweets.d.ts +29 -0
  229. package/dist/types/raw/query/tweet/Retweets.js +3 -0
  230. package/dist/types/raw/query/tweet/Retweets.js.map +1 -0
  231. package/dist/types/raw/query/tweet/Search.d.ts +40 -0
  232. package/dist/types/raw/query/tweet/Search.js +3 -0
  233. package/dist/types/raw/query/tweet/Search.js.map +1 -0
  234. package/dist/types/raw/query/tweet/TweetDetails.d.ts +34 -0
  235. package/dist/types/raw/query/tweet/TweetDetails.js +5 -0
  236. package/dist/types/raw/query/tweet/TweetDetails.js.map +1 -0
  237. package/dist/types/raw/query/tweet/TweetLike.d.ts +29 -0
  238. package/dist/types/raw/query/tweet/TweetLike.js +3 -0
  239. package/dist/types/raw/query/tweet/TweetLike.js.map +1 -0
  240. package/dist/types/raw/query/tweet/TweetLikes.d.ts +29 -0
  241. package/dist/types/raw/query/tweet/TweetLikes.js +3 -0
  242. package/dist/types/raw/query/tweet/TweetLikes.js.map +1 -0
  243. package/dist/types/raw/query/tweet/TweetRetweets.d.ts +0 -0
  244. package/dist/types/raw/query/tweet/TweetRetweets.js +2 -0
  245. package/dist/types/raw/query/tweet/TweetRetweets.js.map +1 -0
  246. package/dist/types/raw/query/user/Details.d.ts +34 -0
  247. package/dist/types/raw/query/user/Details.js +3 -0
  248. package/dist/types/raw/query/user/Details.js.map +1 -0
  249. package/dist/types/raw/user/Tweets.d.ts +668 -1584
  250. package/dist/types/services/args/TweetFilter.d.ts +50 -0
  251. package/dist/types/services/args/TweetFilter.js +76 -0
  252. package/dist/types/services/args/TweetFilter.js.map +1 -0
  253. package/package.json +6 -3
  254. package/src/enums/Errors.ts +21 -0
  255. package/src/graphql/enums/Errors.ts +22 -0
  256. package/src/graphql/queries/RootQuery.ts +11 -4
  257. package/src/graphql/resolvers/AccountResolver.ts +3 -3
  258. package/src/graphql/resolvers/ResolverBase.ts +19 -5
  259. package/src/graphql/resolvers/TweetResolver.ts +26 -17
  260. package/src/graphql/resolvers/UserResolver.ts +75 -20
  261. package/src/graphql/types/TweetTypes.ts +2 -2
  262. package/src/graphql/types/UserTypes.ts +4 -4
  263. package/src/index.ts +39 -17
  264. package/src/models/args/TweetFilter.ts +119 -0
  265. package/src/models/args/TweetListArgs.ts +47 -0
  266. package/src/models/args/UserListArgs.ts +47 -0
  267. package/src/models/auth/AuthCookie.ts +43 -0
  268. package/src/models/data/CursoredData.ts +45 -0
  269. package/src/models/data/Tweet.ts +118 -0
  270. package/src/models/data/User.ts +72 -0
  271. package/src/models/errors/DataValidationError.ts +29 -0
  272. package/src/server.ts +9 -10
  273. package/src/services/{accounts → auth}/AccountService.ts +71 -19
  274. package/src/services/auth/AuthService.ts +81 -0
  275. package/src/services/data/TweetService.ts +81 -62
  276. package/src/services/data/UserService.ts +118 -80
  277. package/src/services/helper/Headers.ts +4 -4
  278. package/src/services/helper/Parser.ts +2 -2
  279. package/src/services/helper/extractors/Tweets.ts +7 -7
  280. package/src/services/helper/extractors/Users.ts +60 -5
  281. package/src/services/helper/urls/Users.ts +39 -23
  282. package/src/services/{CacheService.ts → util/CacheService.ts} +4 -1
  283. package/src/services/{FetcherService.ts → util/FetcherService.ts} +19 -11
  284. package/src/types/Args.ts +49 -0
  285. package/src/types/Authentication.ts +29 -7
  286. package/src/types/Resolvers.ts +5 -4
  287. package/src/types/Rettiwt.ts +20 -0
  288. package/src/types/Service.ts +24 -0
  289. package/src/types/Tweet.ts +61 -0
  290. package/src/types/User.ts +48 -0
  291. package/src/types/raw/user/Tweets.ts +1747 -0
  292. package/tsconfig.json +2 -2
  293. package/src/services/AuthService.ts +0 -68
  294. package/src/services/helper/deserializers/Tweets.ts +0 -70
  295. package/src/services/helper/deserializers/Users.ts +0 -26
  296. package/src/types/data/Errors.ts +0 -37
  297. package/src/types/data/Service.ts +0 -55
  298. package/src/types/data/Tweet.ts +0 -123
  299. package/src/types/raw/auth/Cookie.ts +0 -16
  300. /package/src/{types → enums}/HTTP.ts +0 -0
  301. /package/src/services/{accounts → helper/payloads}/LoginFlows.ts +0 -0
package/src/index.ts CHANGED
@@ -1,18 +1,30 @@
1
+ // PACKAGES
2
+ import 'reflect-metadata';
3
+
1
4
  // SERVICES
2
- import { AuthService } from "./services/AuthService";
5
+ import { AuthService } from "./services/auth/AuthService";
3
6
  import { UserService } from "./services/data/UserService";
4
7
  import { TweetService } from "./services/data/TweetService";
5
- import { AccountService } from "./services/accounts/AccountService";
8
+ import { AccountService } from "./services/auth/AccountService";
9
+
10
+ // TYPES
11
+ import { IAuthCookie } from './types/Authentication';
6
12
 
7
13
  /**
8
- * @param cookie The cookie string to use to fetch data
9
- * @returns The API for fetching user and tweet data
14
+ * The instance for fetching data from Twitter.
15
+ *
16
+ * @public
17
+ *
18
+ * @param cookie The cookie to use to fetch data.
19
+ *
20
+ * @returns The API for fetching user and tweet data.
21
+ *
10
22
  * @remarks The cookie can be obtained by using {@link AccountService.login} method.
11
- * To use the {@link AccountService.login} method, create a {@link Rettiwt} instance without passing any cookie string.
23
+ * To use the {@link AccountService.login} method, create a {@link Rettiwt} instance without passing any cookie .
12
24
  * Then use the {@link AccountService.login} method of {@link AccountService} to get the cookie.
13
25
  */
14
- export const Rettiwt = (cookie: string = '') => {
15
- // Creating new auth service instance using the given cookie string
26
+ export const Rettiwt = (cookie?: IAuthCookie) => {
27
+ // Creating new auth service instance using the given cookie
16
28
  const auth: AuthService = new AuthService(cookie);
17
29
 
18
30
  // Using the auth service instance to create data services instances
@@ -24,17 +36,27 @@ export const Rettiwt = (cookie: string = '') => {
24
36
  }
25
37
 
26
38
  // Exporting classes
27
- export * from './services/AuthService';
28
- export * from './services/CacheService';
29
- export * from './services/FetcherService';
30
- export * from './services/accounts/AccountService';
39
+ export * from './services/auth/AuthService';
40
+ export * from './services/auth/AccountService';
31
41
  export * from './services/data/TweetService';
32
42
  export * from './services/data/UserService';
43
+ export * from './services/util/CacheService';
44
+ export * from './services/util/FetcherService';
33
45
 
34
46
  // Exporting types
35
- export * from './types/data/Errors';
36
- export * from './types/data/Service';
37
- export * from './types/data/Tweet';
38
- export * from './types/data/User';
39
- export * from './types/Authentication';
40
- export * from './types/HTTP';
47
+ export * from './types/Args';
48
+ export { IAuthCookie } from './types/Authentication';
49
+ export * from './types/Rettiwt';
50
+ export * from './types/Service';
51
+ export * from './types/Tweet';
52
+ export * from './types/User';
53
+
54
+ // Exporting models
55
+ export * from './models/args/TweetFilter';
56
+ export * from './models/args/TweetListArgs';
57
+ export * from './models/args/UserListArgs';
58
+ export * from './models/auth/AuthCookie';
59
+ export * from './models/data/CursoredData';
60
+ export * from './models/data/Tweet';
61
+ export * from './models/data/User';
62
+ export * from './models/errors/DataValidationError';
@@ -0,0 +1,119 @@
1
+ // PACKAGE
2
+ import { IsArray, IsBoolean, IsNumberString, IsString, IsOptional, IsDateString, validateSync } from 'class-validator';
3
+
4
+ // TYPES
5
+ import { ITweetFilter } from '../../types/Args';
6
+ import { DataValidationError } from '../errors/DataValidationError';
7
+
8
+ /**
9
+ * The filter to be used for fetching tweets from Twitter.
10
+ *
11
+ * @internal
12
+ */
13
+ export class TweetFilter implements ITweetFilter {
14
+ /** The list of words to search. */
15
+ @IsArray()
16
+ @IsString({ each: true })
17
+ @IsOptional()
18
+ words?: string[];
19
+
20
+ /** The list of hashtags to search.
21
+ *
22
+ * @remarks
23
+ * '#' must be excluded from the hashtag!
24
+ */
25
+ @IsArray()
26
+ @IsString({ each: true })
27
+ @IsOptional()
28
+ hashtags?: string[];
29
+
30
+ /** The list of usernames whose tweets are to be searched.
31
+ *
32
+ * @remarks
33
+ * '@' must be excluded from the username!
34
+ */
35
+ @IsArray()
36
+ @IsString({ each: true })
37
+ @IsOptional()
38
+ fromUsers?: string[];
39
+
40
+ /** The list of username to whom the tweets to be searched, are adressed.
41
+ *
42
+ * @remarks
43
+ * '@' must be excluded from the username!
44
+ */
45
+ @IsArray()
46
+ @IsString({ each: true })
47
+ @IsOptional()
48
+ toUsers?: string[];
49
+
50
+ /** The list of username mentioned in the tweets to search.
51
+ *
52
+ * @remarks
53
+ * '@' must be excluded from the username!
54
+ */
55
+ @IsArray()
56
+ @IsString({ each: true })
57
+ @IsOptional()
58
+ mentions?: string[];
59
+
60
+ /** The date starting from which tweets are to be searched.
61
+ *
62
+ * @remarks
63
+ * Must be in the format YYYY-MM-DD.
64
+ */
65
+ @IsOptional()
66
+ @IsDateString()
67
+ startDate?: string;
68
+
69
+ /** The date upto which tweets are to be searched.
70
+ *
71
+ * @remarks
72
+ * Must be in the format YYYY-MM-DD.
73
+ */
74
+ @IsOptional()
75
+ @IsDateString()
76
+ endDate?: string;
77
+
78
+ /** The id of the tweet, after which the tweets are to be searched. */
79
+ @IsNumberString()
80
+ @IsOptional()
81
+ sinceId?: string;
82
+
83
+ /** The id of the tweet which is quoted in the tweets to search. */
84
+ @IsNumberString()
85
+ @IsOptional()
86
+ quoted?: string;
87
+
88
+ /** Whether to fetch tweets that are links or not.
89
+ *
90
+ * @defaultValue false
91
+ */
92
+ @IsBoolean()
93
+ @IsOptional()
94
+ links?: boolean;
95
+
96
+ /**
97
+ * @param filter The incoming filter in JSON format.
98
+ */
99
+ constructor(filter: TweetFilter) {
100
+ this.endDate = filter.endDate;
101
+ this.fromUsers = filter.fromUsers;
102
+ this.hashtags = filter.hashtags;
103
+ this.links = filter.links;
104
+ this.mentions = filter.mentions;
105
+ this.quoted = filter.quoted;
106
+ this.sinceId = filter.sinceId;
107
+ this.startDate = filter.startDate;
108
+ this.toUsers = filter.toUsers;
109
+ this.words = filter.words;
110
+
111
+ // Validating the filter
112
+ const validationResult = validateSync(this);
113
+
114
+ // If valiation error occured
115
+ if (validationResult.length) {
116
+ throw new DataValidationError(validationResult);
117
+ }
118
+ }
119
+ }
@@ -0,0 +1,47 @@
1
+ // PACKAGES
2
+ import { IsInt, IsString, IsOptional, Min, validateSync, Max, ValidateIf } from 'class-validator';
3
+
4
+ // TYPES
5
+ import { IListArgs } from '../../types/Args';
6
+ import { DataValidationError } from '../errors/DataValidationError';
7
+
8
+ /**
9
+ * The arguments for fetching cursored list in TweetService.
10
+ *
11
+ * @internal
12
+ */
13
+ export class TweetListArgs implements IListArgs {
14
+ /** The number of data items to fetch.
15
+ *
16
+ * @defaultValue 10
17
+ * @remarks Must be >= 10 and <= 100
18
+ */
19
+ @IsInt()
20
+ @IsOptional()
21
+ @Max(100)
22
+ @ValidateIf(ob => ob.cursor.length == 0)
23
+ @Min(10)
24
+ count: number;
25
+
26
+ /** The cursor to the batch of data to fetch. */
27
+ @IsString()
28
+ @IsOptional()
29
+ cursor: string;
30
+
31
+ /**
32
+ * @param count The number of data items to fetch.
33
+ * @param cursor The cursor to the batch of data to fetch.
34
+ */
35
+ constructor(count: number = 10, cursor: string = '') {
36
+ this.count = count;
37
+ this.cursor = cursor;
38
+
39
+ // Validating the arguments
40
+ const validationResult = validateSync(this);
41
+
42
+ // If valiation error occured
43
+ if (validationResult.length) {
44
+ throw new DataValidationError(validationResult);
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,47 @@
1
+ // PACKAGES
2
+ import { IsInt, IsString, IsOptional, Min, validateSync, Max, ValidateIf } from 'class-validator';
3
+
4
+ // TYPES
5
+ import { IListArgs } from '../../types/Args';
6
+ import { DataValidationError } from '../errors/DataValidationError';
7
+
8
+ /**
9
+ * The arguments for fetching cursored list in TweetService.
10
+ *
11
+ * @internal
12
+ */
13
+ export class UserListArgs implements IListArgs {
14
+ /** The number of data items to fetch.
15
+ *
16
+ * @defaultValue 40
17
+ * @remarks Must be >= 40 and <= 100
18
+ */
19
+ @IsInt()
20
+ @IsOptional()
21
+ @Max(100)
22
+ @ValidateIf(ob => ob.cursor.length == 0)
23
+ @Min(40)
24
+ count: number;
25
+
26
+ /** The cursor to the batch of data to fetch. */
27
+ @IsString()
28
+ @IsOptional()
29
+ cursor: string;
30
+
31
+ /**
32
+ * @param count The number of data items to fetch.
33
+ * @param cursor The cursor to the batch of data to fetch.
34
+ */
35
+ constructor(count: number = 40, cursor: string = '') {
36
+ this.count = count;
37
+ this.cursor = cursor;
38
+
39
+ // Validating the arguments
40
+ const validationResult = validateSync(this);
41
+
42
+ // If valiation error occured
43
+ if (validationResult.length) {
44
+ throw new DataValidationError(validationResult);
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,43 @@
1
+ // TYPES
2
+ import { IAuthCookie } from '../../types/Authentication';
3
+
4
+ /**
5
+ * The cookie containing the tokens that are used to authenticate against Twitter.
6
+ *
7
+ * @internal
8
+ */
9
+ export class AuthCookie implements IAuthCookie {
10
+ /** Token used to authenticate a device. */
11
+ kdt: string;
12
+
13
+ /** Token used to authenticate a user using a Twitter ID. */
14
+ twid: string;
15
+
16
+ /** The CSRF token of the session. */
17
+ ct0: string;
18
+
19
+ /** The authentication token used while logging in to the account. */
20
+ auth_token: string;
21
+
22
+ constructor(cookie?: IAuthCookie) {
23
+ this.auth_token = cookie?.auth_token ?? '';
24
+ this.ct0 = cookie?.ct0 ?? '';
25
+ this.kdt = cookie?.kdt ?? '';
26
+ this.twid = cookie?.twid ?? '';
27
+ }
28
+
29
+ /**
30
+ * @returns The string respresentation of this cookie in the valid cookie string format.
31
+ */
32
+ toString(): string {
33
+ /** The string representation of this cookie. */
34
+ let cookieString: string = '';
35
+
36
+ // Iterating through the (key, value) pairs of this cookie
37
+ for (let [key, value] of Object.entries(this)) {
38
+ cookieString += `${key}=${value};`;
39
+ }
40
+
41
+ return cookieString;
42
+ }
43
+ }
@@ -0,0 +1,45 @@
1
+ // TYPES
2
+ import { ICursor,ICursoredData } from "../../types/Service";
3
+
4
+ /**
5
+ * The cursor to the batch of data to be fetched.
6
+ *
7
+ * @internal
8
+ */
9
+ export class Cursor implements ICursor {
10
+ /** The cursor string. */
11
+ value: string;
12
+
13
+ /**
14
+ * Initializes a new cursor from the given cursor string.
15
+ *
16
+ * @param cursorStr The string representation of the cursor.
17
+ */
18
+ constructor(cursorStr: string) {
19
+ this.value = cursorStr;
20
+ }
21
+ }
22
+
23
+ /**
24
+ * The data that us fetched batch-wise along with a cursor.
25
+ *
26
+ * @internal
27
+ *
28
+ * @typeParam Type - The type of data present in the list.
29
+ */
30
+ export class CursoredData<T> implements ICursoredData<T> {
31
+ /** The list of data of the given type. */
32
+ list: T[];
33
+
34
+ /** The cursor to the next batch of data. */
35
+ next: Cursor;
36
+
37
+ /**
38
+ * @param list The list of data item to store.
39
+ * @param next The cursor to the next batch of data.
40
+ */
41
+ constructor(list: T[] = [], next: string = '') {
42
+ this.list = list;
43
+ this.next = new Cursor(next);
44
+ }
45
+ }
@@ -0,0 +1,118 @@
1
+ // TYPES
2
+ import { ITweet, ITweetEntities } from '../../types/Tweet';
3
+ import { Result as RawTweet, Entities2 as RawTweetEntities } from '../../types/raw/tweet/Tweet';
4
+
5
+ // PARSERS
6
+ import * as Parsers from '../../services/helper/Parser';
7
+
8
+ /**
9
+ * The different types parsed entities like urls, media, mentions, hashtags, etc.
10
+ *
11
+ * @internal
12
+ */
13
+ export class TweetEntities implements ITweetEntities {
14
+ // MEMBER DATA
15
+ /** The list of hashtags mentioned in the tweet. */
16
+ hashtags: string[] = [];
17
+
18
+ /** The list of urls mentioned in the tweet. */
19
+ urls: string[] = [];
20
+
21
+ /** The list of IDs of users mentioned in the tweet. */
22
+ mentionedUsers: string[] = [];
23
+
24
+ /** The list of urls to various media mentioned in the tweet. */
25
+ media: string[] = [];
26
+
27
+ // MEMBER METHODS
28
+ constructor(entities: RawTweetEntities) {
29
+ // Extracting user mentions
30
+ if (entities.user_mentions) {
31
+ for (let user of entities.user_mentions) {
32
+ this.mentionedUsers.push(user.id_str);
33
+ }
34
+ }
35
+
36
+ // Extracting urls
37
+ if (entities.urls) {
38
+ for (let url of entities.urls) {
39
+ this.urls.push(url.expanded_url);
40
+ }
41
+ }
42
+
43
+ // Extracting hashtags
44
+ if (entities.hashtags) {
45
+ for (let hashtag of entities.hashtags) {
46
+ this.hashtags.push(hashtag.text);
47
+ }
48
+ }
49
+
50
+ // Extracting media urls (if any)
51
+ if (entities.media) {
52
+ for (const media of entities.media) {
53
+ this.media.push(media.media_url_https);
54
+ }
55
+ }
56
+ }
57
+ }
58
+
59
+ /**
60
+ * The details of a single Tweet.
61
+ *
62
+ * @internal
63
+ */
64
+ export class Tweet implements ITweet {
65
+ /** The rest id of the tweet. */
66
+ id: string;
67
+
68
+ /** The rest id of the user who made the tweet. */
69
+ tweetBy: string;
70
+
71
+ /** The date and time of creation of the tweet, in UTC string format. */
72
+ createdAt: string;
73
+
74
+ /** Additional tweet entities like urls, mentions, etc. */
75
+ entities: TweetEntities;
76
+
77
+ /** The rest id of the tweet which is quoted in the tweet. */
78
+ quoted: string;
79
+
80
+ /** The full text content of the tweet. */
81
+ fullText: string;
82
+
83
+ /** The rest id of the user to which the tweet is a reply. */
84
+ replyTo: string;
85
+
86
+ /** The language in which the tweet is written. */
87
+ lang: string;
88
+
89
+ /** The number of quotes of the tweet. */
90
+ quoteCount: number;
91
+
92
+ /** The number of replies to the tweet. */
93
+ replyCount: number;
94
+
95
+ /** The number of retweets of the tweet. */
96
+ retweetCount: number;
97
+
98
+ /** The number of likes of the tweet. */
99
+ likeCount: number;
100
+
101
+ /**
102
+ * @param tweet The raw tweet data.
103
+ */
104
+ constructor(tweet: RawTweet) {
105
+ this.id = tweet.rest_id;
106
+ this.createdAt = tweet.legacy.created_at;
107
+ this.tweetBy = tweet.legacy.user_id_str;
108
+ this.entities = new TweetEntities(tweet.legacy.entities);
109
+ this.quoted = tweet.legacy.quoted_status_id_str;
110
+ this.fullText = Parsers.normalizeText(tweet.legacy.full_text);
111
+ this.replyTo = tweet.legacy.in_reply_to_status_id_str;
112
+ this.lang = tweet.legacy.lang;
113
+ this.quoteCount = tweet.legacy.quote_count;
114
+ this.replyCount = tweet.legacy.reply_count;
115
+ this.retweetCount = tweet.legacy.retweet_count;
116
+ this.likeCount = tweet.legacy.favorite_count;
117
+ }
118
+ }
@@ -0,0 +1,72 @@
1
+ // TYPES
2
+ import { IUser } from '../../types/User';
3
+ import { Result as RawUser } from '../../types/raw/user/User';
4
+
5
+ /**
6
+ * The details of a single user.
7
+ *
8
+ * @internal
9
+ */
10
+ export class User implements IUser {
11
+ /** The rest id of the user. */
12
+ id: string;
13
+
14
+ /** The username/screenname of the user. */
15
+ userName: string;
16
+
17
+ /** The full name of the user. */
18
+ fullName: string;
19
+
20
+ /** The creation date of user's account. */
21
+ createdAt: string;
22
+
23
+ /** The user's description. */
24
+ description: string;
25
+
26
+ /** Whether the account is verified or not. */
27
+ isVerified: boolean;
28
+
29
+ /** The number of tweets liked by the user. */
30
+ favouritesCount: number;
31
+
32
+ /** The number of followers of the user. */
33
+ followersCount: number;
34
+
35
+ /** The number of following of the user. */
36
+ followingsCount: number;
37
+
38
+ /** The number of tweets made by the user. */
39
+ statusesCount: number;
40
+
41
+ /** The location of user as provided by user. */
42
+ location: string;
43
+
44
+ /** The rest id of the tweet pinned in the user's profile. */
45
+ pinnedTweet: string;
46
+
47
+ /** The url of the profile banner image. */
48
+ profileBanner: string;
49
+
50
+ /** The url of the profile image. */
51
+ profileImage: string;
52
+
53
+ /**
54
+ * @param user The raw user data.
55
+ */
56
+ constructor(user: RawUser) {
57
+ this.id = user.rest_id;
58
+ this.userName = user.legacy.screen_name;
59
+ this.fullName = user.legacy.name;
60
+ this.createdAt = user.legacy.created_at;
61
+ this.description = user.legacy.description;
62
+ this.isVerified = user.legacy.verified;
63
+ this.favouritesCount = user.legacy.favourites_count;
64
+ this.followersCount = user.legacy.followers_count;
65
+ this.followingsCount = user.legacy.friends_count;
66
+ this.statusesCount = user.legacy.statuses_count;
67
+ this.location = user.legacy.location;
68
+ this.pinnedTweet = user.legacy.pinned_tweet_ids_str[0];
69
+ this.profileBanner = user.legacy.profile_banner_url;
70
+ this.profileImage = user.legacy.profile_image_url_https;
71
+ }
72
+ }
@@ -0,0 +1,29 @@
1
+ // PACKAGES
2
+ import { ValidationError } from "class-validator";
3
+
4
+ /**
5
+ * Error when any fields of a JSON data fails to validate.
6
+ *
7
+ * @internal
8
+ *
9
+ * @param errorDetails The details of about the specific fields that failed to validate.
10
+ */
11
+ export class DataValidationError implements Error {
12
+ /** The name of the error. */
13
+ name: string;
14
+
15
+ /** The user-friendly error message. */
16
+ message: string;
17
+
18
+ /** The error data. */
19
+ data: ValidationError[];
20
+
21
+ /**
22
+ * @param data The error details.
23
+ */
24
+ constructor(errorDetails: ValidationError[]) {
25
+ this.name = 'ValidationError';
26
+ this.message = 'One or more validation errors occured. Refer to data for details';
27
+ this.data = errorDetails;
28
+ }
29
+ }
package/src/server.ts CHANGED
@@ -2,12 +2,10 @@
2
2
  import express from 'express';
3
3
  import { graphqlHTTP } from 'express-graphql';
4
4
  import { GraphQLSchema } from 'graphql';
5
+ import 'reflect-metadata';
5
6
 
6
- // Services
7
- import { UserService } from './services/data/UserService';
8
- import { TweetService } from './services/data/TweetService';
9
- import { AccountService } from './services/accounts/AccountService';
10
- import { AuthService } from './services/AuthService';
7
+ // SERVICES
8
+ import { Rettiwt } from '.';
11
9
 
12
10
  // SCHEMA
13
11
  import { rootQuery } from './graphql/queries/RootQuery';
@@ -23,11 +21,12 @@ app.use('/graphql', graphqlHTTP(req => ({
23
21
  schema: new GraphQLSchema({
24
22
  query: rootQuery
25
23
  }),
26
- context: {
27
- users: new UserService(new AuthService(req.headers.cookie as string)),
28
- tweets: new TweetService(new AuthService(req.headers.cookie as string)),
29
- account: new AccountService()
30
- },
24
+ context: Rettiwt({
25
+ auth_token: req.headers['auth_token'] as string,
26
+ ct0: req.headers['ct0'] as string,
27
+ kdt: req.headers['kdt'] as string,
28
+ twid: req.headers['twid'] as string,
29
+ }),
31
30
  // If app is running in development environment, enable graphiql
32
31
  graphiql: config.is_development
33
32
  })));