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
@@ -2,17 +2,18 @@
2
2
  import ResolverBase from './ResolverBase';
3
3
 
4
4
  // TYPES
5
- import { TweetFilter } from '../../types/data/Tweet';
6
- import { Cursor, DataContext } from '../../types/data/Service';
7
- import { DataErrors, ValidationErrors } from '../../types/data/Errors';
5
+ import { IDataContext } from '../../types/Rettiwt'
6
+ import { TweetFilter } from '../../models/args/TweetFilter';
7
+ import { Cursor } from '../../models/data/CursoredData';
8
+ import { DataErrors } from '../enums/Errors';
8
9
 
9
10
  export default class TweetResolver extends ResolverBase {
10
11
  // MEMBER DATA
11
12
  private batchSize: number; // To store the batch size while fetching data
12
13
  // MEMBER METHODS
13
- constructor(context: DataContext) {
14
+ constructor(context: IDataContext) {
14
15
  super(context);
15
- this.batchSize = 20;
16
+ this.batchSize = 100;
16
17
  }
17
18
 
18
19
  /**
@@ -21,7 +22,9 @@ export default class TweetResolver extends ResolverBase {
21
22
  */
22
23
  async resolveTweet(id: string): Promise<any> {
23
24
  // Getting the data
24
- let res = await this.context.tweets.getTweetById(id);
25
+ let res = await this.context.tweets.getTweetDetails(id).catch(error => {
26
+ throw this.getGraphQLError(error);
27
+ });
25
28
 
26
29
  // Evaluating response
27
30
  return res;
@@ -37,22 +40,22 @@ export default class TweetResolver extends ResolverBase {
37
40
  let tweets: any[] = []; // To store the list of tweets
38
41
  let next: Cursor = new Cursor(cursor); // To store cursor to next batch
39
42
  let total: number = 0; // To store the total number of tweets fetched
40
-
41
- // Checking if the given tweet filter is valid or not
42
- if (!(filter.fromUsers || filter.toUsers || filter.words || filter.hashtags || filter.mentions || filter.quoted)) {
43
- throw new Error(ValidationErrors.InvalidTweetFilter);
44
- }
43
+
44
+ /** The batch size while fetching tweets is lower (=20), compared to other data related to a tweet (=100). */
45
+ let batchSize: number = 20; //
45
46
 
46
47
  // If required count less than batch size, setting batch size to required count
47
- this.batchSize = (count < this.batchSize) ? count : this.batchSize;
48
+ batchSize = (count < batchSize) ? count : batchSize;
48
49
 
49
50
  // Repeatedly fetching data as long as total data fetched is less than requried
50
51
  do {
51
52
  // If this is the last batch, change batch size to number of remaining tweets
52
- this.batchSize = ((count - total) < this.batchSize) ? (count - total) : this.batchSize;
53
+ batchSize = ((count - total) < batchSize) ? (count - total) : batchSize;
53
54
 
54
55
  // Getting the data
55
- const res = await this.context.tweets.getTweets(filter, this.batchSize, next.value);
56
+ const res = await this.context.tweets.getTweets(filter, batchSize, next.value ).catch(error => {
57
+ throw this.getGraphQLError(error);
58
+ });
56
59
 
57
60
  // If data is available
58
61
  if (res.list?.length) {
@@ -109,7 +112,9 @@ export default class TweetResolver extends ResolverBase {
109
112
  };
110
113
 
111
114
  // Fetching the quotes using resolveTweets method
112
- quotes = await this.resolveTweets(filter, count, cursor);
115
+ quotes = await this.resolveTweets(filter, count, cursor).catch(error => {
116
+ throw this.getGraphQLError(error);
117
+ });
113
118
 
114
119
  return quotes;
115
120
  }
@@ -139,7 +144,9 @@ export default class TweetResolver extends ResolverBase {
139
144
  this.batchSize = ((count - total) < this.batchSize) ? (count - total) : this.batchSize;
140
145
 
141
146
  // Getting the data
142
- const res = await this.context.tweets.getTweetLikers(id, this.batchSize, next.value);
147
+ const res = await this.context.tweets.getTweetLikers(id, this.batchSize, next.value).catch(error => {
148
+ throw this.getGraphQLError(error);
149
+ });
143
150
 
144
151
  // If data is available
145
152
  if (res.list?.length) {
@@ -194,7 +201,9 @@ export default class TweetResolver extends ResolverBase {
194
201
  this.batchSize = ((count - total) < this.batchSize) ? (count - total) : this.batchSize;
195
202
 
196
203
  // Getting the data
197
- const res = await this.context.tweets.getTweetRetweeters(id, this.batchSize, next.value);
204
+ const res = await this.context.tweets.getTweetRetweeters(id, this.batchSize, next.value).catch(error => {
205
+ throw this.getGraphQLError(error);
206
+ });
198
207
 
199
208
  // If data is available
200
209
  if (res.list?.length) {
@@ -2,15 +2,16 @@
2
2
  import ResolverBase from './ResolverBase';
3
3
 
4
4
  // TYPES
5
- import { Cursor, DataContext } from '../../types/data/Service';
6
- import { DataErrors, ValidationErrors } from '../../types/data/Errors';
5
+ import { IDataContext } from '../../types/Rettiwt'
6
+ import { Cursor } from '../../models/data/CursoredData';
7
+ import { DataErrors } from '../enums/Errors';
7
8
 
8
9
  export default class UserResolver extends ResolverBase {
9
10
  // MEMBER DATA
10
11
  private batchSize: number; // To store the batch size when fetching data
11
12
 
12
13
  // MEMBER METHODS
13
- constructor(context: DataContext) {
14
+ constructor(context: IDataContext) {
14
15
  super(context);
15
16
  this.batchSize = 40;
16
17
  }
@@ -18,21 +19,12 @@ export default class UserResolver extends ResolverBase {
18
19
  /**
19
20
  * @returns The details of the target twitter user
20
21
  * @param userName The user name of the target twitter user
21
- * @param id The id of the target twitter user
22
+ * @param id The id/username of the target twitter user
22
23
  */
23
- async resolveUserDetails(userName: string, id: string): Promise<any> {
24
- // If user name is supplied
25
- if (userName) {
26
- return await this.context.users.getUserDetails(userName);
27
- }
28
- // If id is supplied
29
- else if (id) {
30
- return await this.context.users.getUserDetailsById(id);
31
- }
32
- // If neither userName nor id is supplied
33
- else {
34
- throw new Error(ValidationErrors.NoUserIdentification);
35
- }
24
+ async resolveUserDetails(id: string): Promise<any> {
25
+ return await this.context.users.getUserDetails(id).catch(error => {
26
+ throw this.getGraphQLError(error);
27
+ });
36
28
  }
37
29
 
38
30
  /**
@@ -60,7 +52,9 @@ export default class UserResolver extends ResolverBase {
60
52
  this.batchSize = ((count - total) < this.batchSize) ? (count - total) : this.batchSize;
61
53
 
62
54
  // Getting the data
63
- const res = await this.context.users.getUserLikes(id, this.batchSize, next.value);
55
+ const res = await this.context.users.getUserLikes(id, this.batchSize, next.value).catch(error => {
56
+ throw this.getGraphQLError(error);
57
+ });
64
58
 
65
59
  // If data is available
66
60
  if (res.list?.length) {
@@ -115,7 +109,9 @@ export default class UserResolver extends ResolverBase {
115
109
  this.batchSize = ((count - total) < this.batchSize) ? (count - total) : this.batchSize;
116
110
 
117
111
  // Getting the data
118
- const res = await this.context.users.getUserFollowers(id, this.batchSize, next.value);
112
+ const res = await this.context.users.getUserFollowers(id, this.batchSize, next.value).catch(error => {
113
+ throw this.getGraphQLError(error);
114
+ });
119
115
 
120
116
  // If data is available
121
117
  if (res.list?.length) {
@@ -170,7 +166,9 @@ export default class UserResolver extends ResolverBase {
170
166
  this.batchSize = ((count - total) < this.batchSize) ? (count - total) : this.batchSize;
171
167
 
172
168
  // Getting the data
173
- const res = await this.context.users.getUserFollowing(id, this.batchSize, next.value);
169
+ const res = await this.context.users.getUserFollowing(id, this.batchSize, next.value).catch(error => {
170
+ throw this.getGraphQLError(error);
171
+ });
174
172
 
175
173
  // If data is available
176
174
  if (res.list?.length) {
@@ -17,7 +17,7 @@ export const TweetTokens: GraphQLObjectType = new GraphQLObjectType({
17
17
  urls: { type: new GraphQLList(GraphQLString) },
18
18
  mentionedUsers: {
19
19
  type: UserList,
20
- resolve: (parent, args, context) => parent.mentionedUsers.map((user: string) => new UserResolver(context).resolveUserDetails('', user))
20
+ resolve: (parent, args, context) => parent.mentionedUsers.map((user: string) => new UserResolver(context).resolveUserDetails(user))
21
21
  },
22
22
  media: { type: new GraphQLList(GraphQLString) },
23
23
  })
@@ -30,7 +30,7 @@ export const Tweet: GraphQLObjectType = new GraphQLObjectType({
30
30
  id: { type: GraphQLString },
31
31
  tweetBy: {
32
32
  type: User,
33
- resolve: (parent, args, context) => new UserResolver(context).resolveUserDetails('', parent.tweetBy)
33
+ resolve: (parent, args, context) => new UserResolver(context).resolveUserDetails(parent.tweetBy)
34
34
  },
35
35
  createdAt: { type: GraphQLString },
36
36
  entities: { type: TweetTokens },
@@ -4,7 +4,7 @@ import { GraphQLBoolean, GraphQLObjectType, GraphQLString, GraphQLInt, GraphQLLi
4
4
  // TYPES
5
5
  import { Tweet, TweetList } from './TweetTypes'
6
6
  import { Cursor } from './Global';
7
- import { TweetFilter } from '../../types/data/Tweet';
7
+ import { TweetFilter } from '../../models/args/TweetFilter';
8
8
 
9
9
  // RESOLVERS
10
10
  import UserResolver from '../resolvers/UserResolver';
package/src/index.ts CHANGED
@@ -1,18 +1,30 @@
1
+ // PACKAGES
2
+ import 'reflect-metadata';
3
+
1
4
  // SERVICES
2
- import { AuthService } from "./services/AuthService";
5
+ import { AuthService } from "./services/auth/AuthService";
3
6
  import { UserService } from "./services/data/UserService";
4
7
  import { TweetService } from "./services/data/TweetService";
5
- import { AccountService } from "./services/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
+ }