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,17 +1,23 @@
1
1
  // SERVICES
2
- import { FetcherService } from "../FetcherService";
3
- import { AuthService } from "../AuthService";
2
+ import { FetcherService } from "../util/FetcherService";
3
+ import { AuthService } from "../auth/AuthService";
4
+
5
+ // MODELS
6
+ import { Tweet } from "../../models/data/Tweet";
7
+ import { User } from "../../models/data/User";
8
+ import { TweetListArgs } from "../../models/args/TweetListArgs";
9
+ import { TweetFilter } from "../../models/args/TweetFilter";
10
+ import { CursoredData } from '../../models/data/CursoredData';
4
11
 
5
12
  // TYPES
6
- import { TweetFilter, Tweet } from "../../types/data/Tweet";
7
- import { User } from "../../types/data/User";
8
- import { CursoredData } from '../../types/data/Service';
9
13
  import RawTweet, { Result as TweetData } from '../../types/raw/tweet/Tweet';
10
14
  import { Result as UserData } from "../../types/raw/user/User";
11
15
  import RawTweets from '../../types/raw/tweet/Tweets';
12
16
  import RawLikers from '../../types/raw/tweet/Favouriters';
13
17
  import RawRetweeters from '../../types/raw/tweet/Retweeters';
14
- import * as Errors from '../../types/data/Errors';
18
+
19
+ // ENUMS
20
+ import { AuthenticationErrors } from '../../enums/Errors';
15
21
 
16
22
  // URLS
17
23
  import * as TweetUrls from '../helper/urls/Tweets';
@@ -19,10 +25,6 @@ import * as TweetUrls from '../helper/urls/Tweets';
19
25
  // EXTRACTORS
20
26
  import * as TweetExtractors from "../helper/extractors/Tweets";
21
27
 
22
- // DESERIALIZERS
23
- import * as UserDeserializers from '../helper/deserializers/Users';
24
- import * as TweetDeserializers from '../helper/deserializers/Tweets';
25
-
26
28
  // PARSERS
27
29
  import { toQueryString } from '../helper/Parser';
28
30
 
@@ -31,7 +33,6 @@ import { toQueryString } from '../helper/Parser';
31
33
  * @public
32
34
  */
33
35
  export class TweetService extends FetcherService {
34
- // MEMBER METHODS
35
36
  /**
36
37
  * @param auth The AuthService instance to use for authentication.
37
38
  */
@@ -41,19 +42,24 @@ export class TweetService extends FetcherService {
41
42
 
42
43
  /**
43
44
  * @param filter The filter be used for searching the tweets.
44
- * @param count The number of tweets to fetch.
45
+ * @param count The number of tweets to fetch, must be >= 10 and <= 20
45
46
  * @param cursor The cursor to the next batch of tweets. If blank, first batch is fetched.
47
+ *
46
48
  * @returns The list of tweets that match the given filter.
47
- * @remarks count must be >= 1 and <= 100.
49
+ *
50
+ * @throws {@link Errors.ValidationErrors.InvalidCount} error, if an invalid count has been provided.
51
+ *
52
+ * @remarks
53
+ *
54
+ * If cookies have been provided, then authenticated requests are made. Else, guest requests are made.
48
55
  */
49
- async getTweets(filter: TweetFilter, count: number, cursor: string): Promise<CursoredData<Tweet>> {
50
- // If invalid count provided
51
- if (count < 1 && !cursor) {
52
- throw new Error(Errors.ValidationErrors.InvalidCount);
53
- }
56
+ async getTweets(query: TweetFilter, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
57
+ // Objectifying parameters
58
+ let filter: TweetFilter = new TweetFilter(query);
59
+ let args: TweetListArgs = new TweetListArgs(count, cursor);
54
60
 
55
61
  // Getting the raw data
56
- let res = await this.request<RawTweets>(TweetUrls.tweetsUrl(toQueryString(filter), count, cursor), false).then(res => res.data);
62
+ let res = await this.request<RawTweets>(TweetUrls.tweetsUrl(toQueryString(filter), args.count, args.cursor), this.isAuthenticated).then(res => res.data);
57
63
 
58
64
  // Extracting data
59
65
  let data = TweetExtractors.extractTweets(res);
@@ -62,21 +68,28 @@ export class TweetService extends FetcherService {
62
68
  this.cacheData(data);
63
69
 
64
70
  // Parsing data
65
- let tweets = data.required.map((item: TweetData) => TweetDeserializers.toTweet(item));
71
+ let tweets = data.required.map((item: TweetData) => new Tweet(item));
66
72
 
67
- return {
68
- list: tweets,
69
- next: { value: data.cursor }
70
- };
73
+ // Sorting the tweets by date, from recent to oldest
74
+ tweets.sort((a, b) => new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf());
75
+
76
+ return new CursoredData<Tweet>(tweets, data.cursor);
71
77
  }
72
78
 
73
79
  /**
74
- * @param tweetId The rest id of the target tweet.
80
+ * @param id The id of the target tweet.
81
+ *
75
82
  * @returns The details of a single tweet with the given tweet id.
83
+ *
84
+ * @throws {@link Errors.DataErrors.TweetNotFound} error, if no tweet with the given id was found.
85
+ *
86
+ * @remarks
87
+ *
88
+ * No cookies are required to use this method.
76
89
  */
77
- async getTweetById(tweetId: string): Promise<Tweet> {
90
+ async getTweetDetails(id: string): Promise<Tweet> {
78
91
  // Getting data from cache
79
- let cachedData = await this.readData(tweetId);
92
+ let cachedData = await this.readData(id);
80
93
 
81
94
  // If data exists in cache
82
95
  if (cachedData) {
@@ -84,40 +97,46 @@ export class TweetService extends FetcherService {
84
97
  }
85
98
 
86
99
  // Fetching the raw data
87
- let res = await this.request<RawTweet>(TweetUrls.tweetDetailsUrl(tweetId), false).then(res => res.data);
100
+ let res = await this.request<RawTweet>(TweetUrls.tweetDetailsUrl(id), false).then(res => res.data);
88
101
 
89
102
  // Extracting data
90
- let data = TweetExtractors.extractTweet(res, tweetId);
103
+ let data = TweetExtractors.extractTweet(res, id);
91
104
 
92
105
  // Caching data
93
106
  this.cacheData(data);
94
107
 
95
108
  // Parsing data
96
- let tweet = TweetDeserializers.toTweet(data.required[0]);
109
+ let tweet = new Tweet(data.required[0]);
97
110
 
98
111
  return tweet;
99
112
  }
100
113
 
101
114
  /**
102
115
  * @param tweetId The rest id of the target tweet.
103
- * @param count The batch size of the list.
116
+ * @param count The batch size of the list, must be >= 10 (when no cursor is provided) and <= 20.
104
117
  * @param cursor The cursor to the next batch of users. If blank, first batch is fetched.
118
+ *
105
119
  * @returns The list of users who liked the given tweet.
106
- * @remarks count must be >= 10 (when no cursor is provided) and <= 100.
120
+ *
121
+ * @throws {@link Errors.AuthenticationErrors.NotAuthenticated} error, if no cookies have been provided.
122
+ * @throws {@link Errors.ValidationErrors.InvalidCount} error, if invalid count is provided.
123
+ * @throws {@link Errors.DataErrors.TweetNotFound} error, if no tweet with the given id was found.
124
+ *
125
+ * @remarks
126
+ *
127
+ * Cookies are required to use this method!
107
128
  */
108
- async getTweetLikers(tweetId: string, count: number, cursor: string): Promise<CursoredData<User>> {
129
+ async getTweetLikers(tweetId: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
109
130
  // If user is not authenticated, abort
110
131
  if(!this.isAuthenticated) {
111
- throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
132
+ throw new Error(AuthenticationErrors.NotAuthenticated);
112
133
  }
113
134
 
114
- // If invalid count provided
115
- if (count < 10 && !cursor) {
116
- throw new Error(Errors.ValidationErrors.InvalidCount);
117
- }
135
+ // Objectifying parameters
136
+ let args: TweetListArgs = new TweetListArgs(count, cursor);
118
137
 
119
138
  // Fetching the raw data
120
- let res = await this.request<RawLikers>(TweetUrls.tweetLikesUrl(tweetId, count, cursor)).then(res => res.data);
139
+ let res = await this.request<RawLikers>(TweetUrls.tweetLikesUrl(tweetId, args.count, args.cursor)).then(res => res.data);
121
140
 
122
141
  // Extracting data
123
142
  let data = TweetExtractors.extractTweetLikers(res);
@@ -126,34 +145,37 @@ export class TweetService extends FetcherService {
126
145
  this.cacheData(data);
127
146
 
128
147
  // Parsing data
129
- let users = data.required.map((item: UserData) => UserDeserializers.toUser(item));
148
+ let users = data.required.map((item: UserData) => new User(item));
130
149
 
131
- return {
132
- list: users,
133
- next: { value: data.cursor }
134
- };
150
+ return new CursoredData<User>(users, data.cursor);
135
151
  }
136
152
 
137
153
  /**
138
154
  * @param tweetId The rest id of the target tweet.
139
- * @param count The batch size of the list.
155
+ * @param count The batch size of the list, must be >= 10 (when no cursor is provided) and <= 100.
140
156
  * @param cursor The cursor to the next batch of users. If blank, first batch is fetched.
157
+ *
141
158
  * @returns The list of users who retweeted the given tweet.
142
- * @remarks count must be >= 10 (when no cursor is provided) and <= 100.
159
+ *
160
+ * @throws {@link Errors.AuthenticationErrors.NotAuthenticated} error, if no cookies have been provided.
161
+ * @throws {@link Errors.ValidationErrors.InvalidCount} error, if invalid count is provided.
162
+ * @throws {@link Errors.DataErrors.TweetNotFound} error, if no tweet with the given id was found.
163
+ *
164
+ * @remarks
165
+ *
166
+ * Cookies are required to use this method!
143
167
  */
144
- async getTweetRetweeters(tweetId: string, count: number, cursor: string): Promise<CursoredData<User>> {
168
+ async getTweetRetweeters(tweetId: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
145
169
  // If user is not authenticated, abort
146
170
  if(!this.isAuthenticated) {
147
- throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
171
+ throw new Error(AuthenticationErrors.NotAuthenticated);
148
172
  }
149
173
 
150
- // If invalid count provided
151
- if (count < 10 && !cursor) {
152
- throw new Error(Errors.ValidationErrors.InvalidCount);
153
- }
174
+ // Objectifying parameters
175
+ let args: TweetListArgs = new TweetListArgs(count, cursor);
154
176
 
155
177
  // Fetching the raw data
156
- let res = await this.request<RawRetweeters>(TweetUrls.tweetRetweetUrl(tweetId, count, cursor)).then(res => res.data);
178
+ let res = await this.request<RawRetweeters>(TweetUrls.tweetRetweetUrl(tweetId, args.count, args.cursor)).then(res => res.data);
157
179
 
158
180
  // Extracting data
159
181
  let data = TweetExtractors.extractTweetRetweeters(res);
@@ -162,12 +184,9 @@ export class TweetService extends FetcherService {
162
184
  this.cacheData(data);
163
185
 
164
186
  // Parsing data
165
- let users = data.required.map((item: UserData) => UserDeserializers.toUser(item));
187
+ let users = data.required.map((item: UserData) => new User(item));
166
188
 
167
- return {
168
- list: users,
169
- next: { value: data.cursor }
170
- };
189
+ return new CursoredData<User>(users, data.cursor);
171
190
  }
172
191
 
173
192
  /**
@@ -1,17 +1,22 @@
1
1
  // SERVICES
2
- import { FetcherService } from '../FetcherService';
3
- import { AuthService } from '../AuthService';
2
+ import { FetcherService } from '../util/FetcherService';
3
+ import { AuthService } from '../auth/AuthService';
4
+
5
+ // MODELS
6
+ import { User } from '../../models/data/User';
7
+ import { UserListArgs } from '../../models/args/UserListArgs';
8
+ import { Tweet } from '../../models/data/Tweet';
4
9
 
5
10
  // TYPES
6
- import { User } from '../../types/data/User';
7
- import { Tweet } from '../../types/data/Tweet';
8
- import { CursoredData } from '../../types/data/Service';
11
+ import { CursoredData } from '../../models/data/CursoredData';
9
12
  import { Result as TweetData } from '../../types/raw/tweet/Tweet';
10
13
  import RawUser, { Result as UserData } from '../../types/raw/user/User';
11
14
  import RawUserFollowers from '../../types/raw/user/Followers';
12
15
  import RawUserFollowing from '../../types/raw/user/Following';
13
16
  import RawUserLikes from '../../types/raw/user/Likes';
14
- import * as Errors from '../../types/data/Errors';
17
+
18
+ // ENUMS
19
+ import { AuthenticationErrors } from '../../enums/Errors';
15
20
 
16
21
  // URLS
17
22
  import * as UserUrls from '../helper/urls/Users';
@@ -19,15 +24,10 @@ import * as UserUrls from '../helper/urls/Users';
19
24
  // EXTRACTORS
20
25
  import * as UserExtractors from '../helper/extractors/Users';
21
26
 
22
- // DESERIALIZERS
23
- import * as UserDeserializers from '../helper/deserializers/Users';
24
- import * as TweetDeserializers from '../helper/deserializers/Tweets';
25
-
26
27
  /**
27
28
  * Handles fetching of data related to user account
28
29
  */
29
30
  export class UserService extends FetcherService {
30
- // MEMBER METHODS
31
31
  /**
32
32
  * @param auth The AuthService instance to use for authentication.
33
33
  */
@@ -36,40 +36,37 @@ export class UserService extends FetcherService {
36
36
  }
37
37
 
38
38
  /**
39
- * @param screenName The screen name of the target user.
39
+ * @param id The id/username of the target user.
40
+ *
40
41
  * @returns The details of the given user.
42
+ *
43
+ * @throws {@link Errors.DataErrors.UserNotFound} error, if no user with the given username was found.
44
+ *
45
+ * @remarks
46
+ *
47
+ * No cookies are required to use this method.
41
48
  */
42
- async getUserDetails(screenName: string): Promise<User> {
43
- // Fetching the raw data
44
- let res: RawUser = await this.request<RawUser>(UserUrls.userDetailsUrl(screenName), false).then(res => res.data);
45
-
46
- // Extracting data
47
- let data = UserExtractors.extractUserDetails(res);
48
-
49
- // Caching data
50
- this.cacheData(data);
49
+ async getUserDetails(id: string): Promise<User> {
50
+ let res: RawUser;
51
51
 
52
- // Parsing data
53
- let user = UserDeserializers.toUser(data.required[0]);
54
-
55
- return user;
56
- }
57
-
58
- /**
59
- * @param restId The screen name of the target user.
60
- * @returns The details of the user with given rest id.
61
- */
62
- async getUserDetailsById(restId: string): Promise<User> {
63
- // Getting data from cache
64
- let cachedData = await this.readData(restId);
65
-
66
- // If data exists in cache
67
- if(cachedData) {
68
- return cachedData;
52
+ // If id is not a numeric string => username is supplied
53
+ if (isNaN(Number(id))) {
54
+ // Fetching the raw data
55
+ res = await this.request<RawUser>(UserUrls.userDetailsUrl(id), false).then(res => res.data);
56
+ }
57
+ // If id is a numeric string => id is supplied
58
+ else {
59
+ // Getting data from cache
60
+ let cachedData = await this.readData(id);
61
+
62
+ // If data exists in cache
63
+ if (cachedData) {
64
+ return cachedData;
65
+ }
66
+
67
+ // Fetching the raw data
68
+ res = await this.request<RawUser>(UserUrls.userDetailsByIdUrl(id), false).then(res => res.data);
69
69
  }
70
-
71
- // Fetchin the raw data
72
- let res = await this.request<RawUser>(UserUrls.userDetailsByIdUrl(restId), false).then(res => res.data);
73
70
 
74
71
  // Extracting data
75
72
  let data = UserExtractors.extractUserDetails(res);
@@ -78,32 +75,38 @@ export class UserService extends FetcherService {
78
75
  this.cacheData(data);
79
76
 
80
77
  // Parsing data
81
- let user = UserDeserializers.toUser(data.required[0]);
82
-
78
+ let user = new User(data.required[0]);
79
+
83
80
  return user;
84
81
  }
85
82
 
86
83
  /**
87
84
  * @param userId The rest id of the target user.
88
- * @param count The number of following to fetch.
85
+ * @param count The number of following to fetch, must be >= 40 (when no cursor is provided) and <=100.
89
86
  * @param cursor The cursor to next batch. If blank, first batch is fetched.
87
+ *
90
88
  * @returns The list of users followed by the target user.
91
- * @remarks count must be >= 40 (when no cursor is provided) and <=100.
89
+ *
90
+ * @throws {@link Errors.AuthenticationErrors.NotAuthenticated} error, if no cookies have been provided.
91
+ * @throws {@link Errors.ValidationErrors.InvalidCount} error, if invalid count has been provided.
92
+ * @throws {@link Errors.DataErrors.UserNotFound} error, if invalid count has been provided.
93
+ *
94
+ * @remarks
95
+ *
96
+ * Cookies are required to use this method!
92
97
  */
93
- async getUserFollowing(userId: string, count: number, cursor: string): Promise<CursoredData<User>> {
98
+ async getUserFollowing(userId: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
94
99
  // If user is not authenticated, abort
95
- if(!this.isAuthenticated) {
96
- throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
100
+ if (!this.isAuthenticated) {
101
+ throw new Error(AuthenticationErrors.NotAuthenticated);
97
102
  }
98
103
 
99
- // If invalid count provided
100
- if (count < 40 && !cursor) {
101
- throw new Error(Errors.ValidationErrors.InvalidCount);
102
- }
104
+ // Objectifying parameters
105
+ let args: UserListArgs = new UserListArgs(count, cursor);
103
106
 
104
107
  // Fetchin the raw data
105
- let res = await this.request<RawUserFollowing>(UserUrls.userFollowingUrl(userId, count, cursor)).then(res => res.data);
106
-
108
+ let res = await this.request<RawUserFollowing>(UserUrls.userFollowingUrl(userId, args.count, args.cursor)).then(res => res.data);
109
+
107
110
  // Extracting data
108
111
  let data = UserExtractors.extractUserFollow(res);
109
112
 
@@ -111,35 +114,38 @@ export class UserService extends FetcherService {
111
114
  this.cacheData(data);
112
115
 
113
116
  // Parsing data
114
- let users = data.required.map((item: UserData) => UserDeserializers.toUser(item));
117
+ let users = data.required.map((item: UserData) => new User(item));
115
118
 
116
- return {
117
- list: users,
118
- next: { value: data.cursor }
119
- };
119
+ return new CursoredData<User>(users, data.cursor);
120
120
  }
121
121
 
122
122
  /**
123
123
  * @param userId The rest id of the target user.
124
- * @param count The number of followers to fetch.
124
+ * @param count The number of followers to fetch, must be >= 40 (when no cursor is provided) and <=100.
125
125
  * @param cursor The cursor to next batch. If blank, first batch is fetched.
126
+ *
126
127
  * @returns The list of users following the target user.
127
- * @remarks count must be >= 40 (when no cursor is provided) and <=100.
128
+ *
129
+ * @throws {@link Errors.AuthenticationErrors.NotAuthenticated} error, if no cookies have been provided.
130
+ * @throws {@link Errors.ValidationErrors.InvalidCount} error, if invalid count has been provided.
131
+ * @throws {@link Errors.DataErrors.UserNotFound} error, if invalid count has been provided.
132
+ *
133
+ * @remarks
134
+ *
135
+ * Cookies are required to use this method!
128
136
  */
129
- async getUserFollowers(userId: string, count: number, cursor: string): Promise<CursoredData<User>> {
137
+ async getUserFollowers(userId: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
130
138
  // If user is not authenticated, abort
131
139
  if (!this.isAuthenticated) {
132
- throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
140
+ throw new Error(AuthenticationErrors.NotAuthenticated);
133
141
  }
134
142
 
135
- // If invalid count provided
136
- if (count < 40 && !cursor) {
137
- throw new Error(Errors.ValidationErrors.InvalidCount);
138
- }
143
+ // Objectifying parameters
144
+ let args: UserListArgs = new UserListArgs(count, cursor);
139
145
 
140
146
  // Fetching the raw data
141
- let res = await this.request<RawUserFollowers>(UserUrls.userFollowersUrl(userId, count, cursor)).then(res => res.data);
142
-
147
+ let res = await this.request<RawUserFollowers>(UserUrls.userFollowersUrl(userId, args.count, args.cursor)).then(res => res.data);
148
+
143
149
  // Extracting data
144
150
  let data = UserExtractors.extractUserFollow(res);
145
151
 
@@ -147,35 +153,36 @@ export class UserService extends FetcherService {
147
153
  this.cacheData(data);
148
154
 
149
155
  // Parsing data
150
- let users = data.required.map((item: UserData) => UserDeserializers.toUser(item));
156
+ let users = data.required.map((item: UserData) => new User(item));
151
157
 
152
- return {
153
- list: users,
154
- next: { value: data.cursor }
155
- };
158
+ return new CursoredData<User>(users, data.cursor);
156
159
  }
157
160
 
158
161
  /**
159
162
  * @param userId The rest id of the target user.
160
163
  * @param count The number of likes to fetch.
161
- * @param cursor The cursor to next batch. If blank, first batch is fetched.
164
+ * @param cursor The cursor to next batch. If blank, first batch is fetched, must be >= 40 (when no cursor is provided) and <=100.
165
+ *
162
166
  * @returns The list of tweets liked by the target user.
163
- * @remarks count must be >= 40 (when no cursor is provided) and <= 100.
167
+ *
168
+ * @throws {@link AuthenticationErrors.NotAuthenticated} error, if no cookies have been provided.
169
+ *
170
+ * @remarks
171
+ *
172
+ * Cookies are required to use this method!
164
173
  */
165
- async getUserLikes(userId: string, count: number, cursor: string): Promise<CursoredData<Tweet>> {
174
+ async getUserLikes(userId: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
166
175
  // If user is not authenticated, abort
167
176
  if (!this.isAuthenticated) {
168
- throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
177
+ throw new Error(AuthenticationErrors.NotAuthenticated);
169
178
  }
170
179
 
171
- // If invalid count provided
172
- if (count < 40 && !cursor) {
173
- throw new Error(Errors.ValidationErrors.InvalidCount);
174
- }
180
+ // Objectifying parameters
181
+ let args: UserListArgs = new UserListArgs(count, cursor);
175
182
 
176
183
  // Fetching the raw data
177
- let res = await this.request<RawUserLikes>(UserUrls.userLikesUrl(userId, count, cursor)).then(res => res.data);
178
-
184
+ let res = await this.request<RawUserLikes>(UserUrls.userLikesUrl(userId, args.count, args.cursor)).then(res => res.data);
185
+
179
186
  // Extracting data
180
187
  let data = UserExtractors.extractUserLikes(res);
181
188
 
@@ -183,11 +190,8 @@ export class UserService extends FetcherService {
183
190
  this.cacheData(data);
184
191
 
185
192
  // Parsing data
186
- let tweets = data.required.map((item: TweetData) => TweetDeserializers.toTweet(item));
193
+ let tweets = data.required.map((item: TweetData) => new Tweet(item));
187
194
 
188
- return {
189
- list: tweets,
190
- next: { value: data.cursor }
191
- };
195
+ return new CursoredData<Tweet>(tweets, data.cursor);
192
196
  }
193
197
  };
@@ -1,5 +1,5 @@
1
1
  // TYPES
2
- import { GuestCredentials, AuthCredentials } from '../../types/Authentication';
2
+ import { IGuestCredentials, IAuthCredentials } from '../../types/Authentication';
3
3
 
4
4
  /**
5
5
  * @param authToken The authentication token received from Twitter
@@ -7,7 +7,7 @@ import { GuestCredentials, AuthCredentials } from '../../types/Authentication';
7
7
  * @param cookie The cookie associated with the logged in account
8
8
  * @returns The header required for making authorized HTTP requests
9
9
  */
10
- export function authorizedHeader(authCred: AuthCredentials): any {
10
+ export function authorizedHeader(authCred: IAuthCredentials): any {
11
11
  return [
12
12
  `sec-ch-ua: "Not_A Brand";v="99", "Microsoft Edge";v="109", "Chromium";v="109"`,
13
13
  `x-twitter-client-language: en`,
@@ -28,7 +28,7 @@ export function authorizedHeader(authCred: AuthCredentials): any {
28
28
  * @param guestCred The guest credentials to use
29
29
  * @returns The header requred for making guest HTTP requests
30
30
  */
31
- export function guestHeader(guestCred: GuestCredentials): any {
31
+ export function guestHeader(guestCred: IGuestCredentials): any {
32
32
  return [
33
33
  'Accept: */*',
34
34
  `authorization: ${guestCred.authToken}`,
@@ -42,7 +42,7 @@ export function guestHeader(guestCred: GuestCredentials): any {
42
42
  * @param cookie The cookie to be used
43
43
  * @returns The header for making HTTP request for logging in
44
44
  */
45
- export function loginHeader(guestCred: GuestCredentials, cookie: string): any {
45
+ export function loginHeader(guestCred: IGuestCredentials, cookie: string): any {
46
46
  return [
47
47
  `sec-ch-ua: "Not_A Brand";v="99", "Microsoft Edge";v="109", "Chromium";v="109"`,
48
48
  `x-twitter-client-language: en`,
@@ -1,5 +1,5 @@
1
1
  // TYPES
2
- import { TweetFilter } from '../../types/data/Tweet';
2
+ import { ITweetFilter } from '../../types/Args';
3
3
 
4
4
  /**
5
5
  * @returns Whether the given json object is empty or not
@@ -92,7 +92,7 @@ export function normalizeText(text: string): string {
92
92
  * @param filter The tweet filter to use for getting filtered tweets
93
93
  * @returns The same tweet filter, in a URL query format string
94
94
  */
95
- export function toQueryString(filter: TweetFilter): string {
95
+ export function toQueryString(filter: ITweetFilter): string {
96
96
  // Concatenating the input filter arguments to a URL query formatted string
97
97
  return [
98
98
  filter.words ? filter.words.join(' ') : '',
@@ -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 RawTweet from '../../../types/raw/tweet/Tweet';
5
5
  import RawTweets from '../../../types/raw/tweet/Tweets';
6
6
  import RawRetweeters from '../../../types/raw/tweet/Retweeters';
@@ -13,7 +13,7 @@ import * as Parsers from '../Parser';
13
13
  * @returns The raw tweets data formatted and sorted into required and additional data
14
14
  * @param res The raw response received from TwitterAPI
15
15
  */
16
- export function extractTweets(res: RawTweets): DataExtract {
16
+ export function extractTweets(res: RawTweets): 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
@@ -63,7 +63,7 @@ export function extractTweets(res: RawTweets): DataExtract {
63
63
  * @param res The raw response received from TwitterAPI
64
64
  * @param tweetId The rest id of the tweet to fetch
65
65
  */
66
- export function extractTweet(res: RawTweet, tweetId: string): DataExtract {
66
+ export function extractTweet(res: RawTweet, tweetId: string): IDataExtract {
67
67
  let required: any[] = []; // To store the reqruied raw data
68
68
  let cursor: string = ''; // To store the cursor to next batch
69
69
  let users: any[] = []; // To store additional user data
@@ -112,7 +112,7 @@ export function extractTweet(res: RawTweet, tweetId: string): DataExtract {
112
112
  * @returns The raw tweet likers data formatted and sorted into required and additional data
113
113
  * @param res The raw response received from TwitterAPI
114
114
  */
115
- export function extractTweetLikers(res: RawLikers): DataExtract {
115
+ export function extractTweetLikers(res: RawLikers): IDataExtract {
116
116
  let required: any[] = []; // To store the reqruied raw data
117
117
  let cursor: string = ''; // To store the cursor to next batch
118
118
  let users: any[] = []; // To store additional user data
@@ -152,7 +152,7 @@ export function extractTweetLikers(res: RawLikers): DataExtract {
152
152
  * @returns The raw tweet retweeters data formatted and sorted into required and additional data
153
153
  * @param res The raw response received from TwitterAPI
154
154
  */
155
- export function extractTweetRetweeters(res: RawRetweeters): DataExtract {
155
+ export function extractTweetRetweeters(res: RawRetweeters): IDataExtract {
156
156
  let required: any[] = []; // To store the reqruied raw data
157
157
  let cursor: string = ''; // To store the cursor to next batch
158
158
  let users: any[] = []; // To store additional user data
@@ -193,7 +193,7 @@ export function extractTweetRetweeters(res: RawRetweeters): DataExtract {
193
193
  * @param res The raw response received from TwitterAPI
194
194
  * @param tweetId The id of the tweet whose replies must be extracted
195
195
  */
196
- export function extractTweetReplies(res: RawTweet, tweetId: string): DataExtract {
196
+ export function extractTweetReplies(res: RawTweet, tweetId: string): IDataExtract {
197
197
  let required: any[] = []; // To store the reqruied raw data
198
198
  let cursor: string = ''; // To store the cursor to next batch
199
199
  let users: any[] = []; // To store additional user data