rettiwt-api 1.4.0 → 2.0.0

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 (232) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.js +54 -0
  3. package/.github/workflows/documentation.yml +29 -9
  4. package/.github/workflows/publish.yml +8 -3
  5. package/.prettierignore +3 -0
  6. package/.prettierrc +13 -0
  7. package/README.md +59 -61
  8. package/dist/Rettiwt.d.ts +19 -0
  9. package/dist/Rettiwt.js +30 -0
  10. package/dist/Rettiwt.js.map +1 -0
  11. package/dist/enums/ApiErrors.d.ts +30 -0
  12. package/dist/enums/ApiErrors.js +35 -0
  13. package/dist/enums/ApiErrors.js.map +1 -0
  14. package/dist/enums/HTTP.d.ts +11 -11
  15. package/dist/enums/HTTP.js +15 -16
  16. package/dist/enums/HTTP.js.map +1 -1
  17. package/dist/helper/JsonUtils.d.ts +26 -0
  18. package/dist/helper/JsonUtils.js +88 -0
  19. package/dist/helper/JsonUtils.js.map +1 -0
  20. package/dist/index.d.ts +10 -43
  21. package/dist/index.js +16 -55
  22. package/dist/index.js.map +1 -1
  23. package/dist/models/CursoredData.d.ts +37 -0
  24. package/dist/models/CursoredData.js +59 -0
  25. package/dist/models/CursoredData.js.map +1 -0
  26. package/dist/models/{data/Tweet.d.ts → Tweet.d.ts} +4 -4
  27. package/dist/models/{data/Tweet.js → Tweet.js} +7 -32
  28. package/dist/models/Tweet.js.map +1 -0
  29. package/dist/models/{data/User.d.ts → User.d.ts} +3 -3
  30. package/dist/models/{data/User.js → User.js} +3 -3
  31. package/dist/models/User.js.map +1 -0
  32. package/dist/services/FetcherService.d.ts +66 -0
  33. package/dist/services/FetcherService.js +207 -0
  34. package/dist/services/FetcherService.js.map +1 -0
  35. package/dist/services/TweetService.d.ts +88 -0
  36. package/dist/services/TweetService.js +244 -0
  37. package/dist/services/TweetService.js.map +1 -0
  38. package/dist/services/UserService.d.ts +60 -0
  39. package/dist/services/UserService.js +188 -0
  40. package/dist/services/UserService.js.map +1 -0
  41. package/dist/types/{Service.d.ts → CursoredData.d.ts} +3 -3
  42. package/dist/types/CursoredData.js +3 -0
  43. package/dist/types/CursoredData.js.map +1 -0
  44. package/dist/types/Tweet.js +1 -1
  45. package/dist/types/User.js +1 -1
  46. package/package.json +15 -19
  47. package/src/Rettiwt.ts +33 -0
  48. package/src/enums/ApiErrors.ts +30 -0
  49. package/src/enums/HTTP.ts +12 -12
  50. package/src/helper/JsonUtils.ts +86 -0
  51. package/src/index.ts +14 -57
  52. package/src/models/CursoredData.ts +64 -0
  53. package/src/models/Tweet.ts +116 -0
  54. package/src/models/User.ts +72 -0
  55. package/src/services/FetcherService.ts +183 -0
  56. package/src/services/TweetService.ts +153 -0
  57. package/src/services/UserService.ts +117 -0
  58. package/src/types/CursoredData.ts +24 -0
  59. package/src/types/Tweet.ts +35 -35
  60. package/src/types/User.ts +30 -30
  61. package/tsconfig.json +9 -9
  62. package/dist/config/env.d.ts +0 -5
  63. package/dist/config/env.js +0 -9
  64. package/dist/config/env.js.map +0 -1
  65. package/dist/enums/Errors.d.ts +0 -21
  66. package/dist/enums/Errors.js +0 -29
  67. package/dist/enums/Errors.js.map +0 -1
  68. package/dist/graphql/enums/Errors.d.ts +0 -21
  69. package/dist/graphql/enums/Errors.js +0 -29
  70. package/dist/graphql/enums/Errors.js.map +0 -1
  71. package/dist/graphql/queries/RootQuery.d.ts +0 -4
  72. package/dist/graphql/queries/RootQuery.js +0 -83
  73. package/dist/graphql/queries/RootQuery.js.map +0 -1
  74. package/dist/graphql/resolvers/AccountResolver.d.ts +0 -12
  75. package/dist/graphql/resolvers/AccountResolver.js +0 -84
  76. package/dist/graphql/resolvers/AccountResolver.js.map +0 -1
  77. package/dist/graphql/resolvers/ResolverBase.d.ts +0 -16
  78. package/dist/graphql/resolvers/ResolverBase.js +0 -23
  79. package/dist/graphql/resolvers/ResolverBase.js.map +0 -1
  80. package/dist/graphql/resolvers/TweetResolver.d.ts +0 -46
  81. package/dist/graphql/resolvers/TweetResolver.js +0 -302
  82. package/dist/graphql/resolvers/TweetResolver.js.map +0 -1
  83. package/dist/graphql/resolvers/UserResolver.d.ts +0 -48
  84. package/dist/graphql/resolvers/UserResolver.js +0 -334
  85. package/dist/graphql/resolvers/UserResolver.js.map +0 -1
  86. package/dist/graphql/types/Global.d.ts +0 -4
  87. package/dist/graphql/types/Global.js +0 -13
  88. package/dist/graphql/types/Global.js.map +0 -1
  89. package/dist/graphql/types/TweetTypes.d.ts +0 -4
  90. package/dist/graphql/types/TweetTypes.js +0 -160
  91. package/dist/graphql/types/TweetTypes.js.map +0 -1
  92. package/dist/graphql/types/UserTypes.d.ts +0 -3
  93. package/dist/graphql/types/UserTypes.js +0 -137
  94. package/dist/graphql/types/UserTypes.js.map +0 -1
  95. package/dist/models/args/TweetListArgs.d.ts +0 -21
  96. package/dist/models/args/TweetListArgs.js +0 -54
  97. package/dist/models/args/TweetListArgs.js.map +0 -1
  98. package/dist/models/args/UserListArgs.d.ts +0 -21
  99. package/dist/models/args/UserListArgs.js +0 -54
  100. package/dist/models/args/UserListArgs.js.map +0 -1
  101. package/dist/models/auth/AuthCookie.d.ts +0 -21
  102. package/dist/models/auth/AuthCookie.js +0 -33
  103. package/dist/models/auth/AuthCookie.js.map +0 -1
  104. package/dist/models/data/CursoredData.d.ts +0 -34
  105. package/dist/models/data/CursoredData.js +0 -42
  106. package/dist/models/data/CursoredData.js.map +0 -1
  107. package/dist/models/data/Tweet.js.map +0 -1
  108. package/dist/models/data/User.js.map +0 -1
  109. package/dist/server.d.ts +0 -1
  110. package/dist/server.js +0 -76
  111. package/dist/server.js.map +0 -1
  112. package/dist/services/auth/AccountService.d.ts +0 -83
  113. package/dist/services/auth/AccountService.js +0 -412
  114. package/dist/services/auth/AccountService.js.map +0 -1
  115. package/dist/services/auth/AuthService.d.ts +0 -31
  116. package/dist/services/auth/AuthService.js +0 -118
  117. package/dist/services/auth/AuthService.js.map +0 -1
  118. package/dist/services/data/TweetService.d.ts +0 -60
  119. package/dist/services/data/TweetService.js +0 -250
  120. package/dist/services/data/TweetService.js.map +0 -1
  121. package/dist/services/data/UserService.d.ts +0 -71
  122. package/dist/services/data/UserService.js +0 -278
  123. package/dist/services/data/UserService.js.map +0 -1
  124. package/dist/services/helper/Headers.d.ts +0 -19
  125. package/dist/services/helper/Headers.js +0 -62
  126. package/dist/services/helper/Headers.js.map +0 -1
  127. package/dist/services/helper/Parser.d.ts +0 -22
  128. package/dist/services/helper/Parser.js +0 -84
  129. package/dist/services/helper/Parser.js.map +0 -1
  130. package/dist/services/helper/extractors/Tweets.d.ts +0 -23
  131. package/dist/services/helper/extractors/Tweets.js +0 -200
  132. package/dist/services/helper/extractors/Tweets.js.map +0 -1
  133. package/dist/services/helper/extractors/Users.d.ts +0 -17
  134. package/dist/services/helper/extractors/Users.js +0 -151
  135. package/dist/services/helper/extractors/Users.js.map +0 -1
  136. package/dist/services/helper/payloads/LoginFlows.d.ts +0 -77
  137. package/dist/services/helper/payloads/LoginFlows.js +0 -92
  138. package/dist/services/helper/payloads/LoginFlows.js.map +0 -1
  139. package/dist/services/helper/urls/Authentication.d.ts +0 -4
  140. package/dist/services/helper/urls/Authentication.js +0 -11
  141. package/dist/services/helper/urls/Authentication.js.map +0 -1
  142. package/dist/services/util/CacheService.d.ts +0 -33
  143. package/dist/services/util/CacheService.js +0 -96
  144. package/dist/services/util/CacheService.js.map +0 -1
  145. package/dist/services/util/FetcherService.d.ts +0 -65
  146. package/dist/services/util/FetcherService.js +0 -202
  147. package/dist/services/util/FetcherService.js.map +0 -1
  148. package/dist/types/Args.d.ts +0 -11
  149. package/dist/types/Args.js +0 -4
  150. package/dist/types/Args.js.map +0 -1
  151. package/dist/types/Authentication.d.ts +0 -55
  152. package/dist/types/Authentication.js +0 -6
  153. package/dist/types/Authentication.js.map +0 -1
  154. package/dist/types/Resolvers.d.ts +0 -15
  155. package/dist/types/Resolvers.js +0 -3
  156. package/dist/types/Resolvers.js.map +0 -1
  157. package/dist/types/Rettiwt.d.ts +0 -16
  158. package/dist/types/Rettiwt.js +0 -3
  159. package/dist/types/Rettiwt.js.map +0 -1
  160. package/dist/types/Service.js +0 -5
  161. package/dist/types/Service.js.map +0 -1
  162. package/docs/.nojekyll +0 -1
  163. package/docs/assets/highlight.css +0 -64
  164. package/docs/assets/main.js +0 -58
  165. package/docs/assets/search.js +0 -1
  166. package/docs/assets/style.css +0 -1280
  167. package/docs/classes/AccountService.html +0 -286
  168. package/docs/classes/AuthCookie.html +0 -146
  169. package/docs/classes/AuthService.html +0 -147
  170. package/docs/classes/CacheService.html +0 -157
  171. package/docs/classes/Cursor.html +0 -102
  172. package/docs/classes/CursoredData.html +0 -126
  173. package/docs/classes/DataValidationError.html +0 -120
  174. package/docs/classes/FetcherService.html +0 -225
  175. package/docs/classes/Tweet.html +0 -210
  176. package/docs/classes/TweetEntities.html +0 -128
  177. package/docs/classes/TweetFilter.html +0 -233
  178. package/docs/classes/TweetListArgs.html +0 -118
  179. package/docs/classes/TweetService.html +0 -319
  180. package/docs/classes/User.html +0 -230
  181. package/docs/classes/UserListArgs.html +0 -118
  182. package/docs/classes/UserService.html +0 -355
  183. package/docs/enums/HttpMethods.html +0 -74
  184. package/docs/functions/Rettiwt.html +0 -100
  185. package/docs/index.html +0 -159
  186. package/docs/interfaces/IAuthCookie.html +0 -104
  187. package/docs/interfaces/ICursor.html +0 -77
  188. package/docs/interfaces/ICursoredData.html +0 -93
  189. package/docs/interfaces/IDataContext.html +0 -91
  190. package/docs/interfaces/IDataValidationError.html +0 -109
  191. package/docs/interfaces/IListArgs.html +0 -87
  192. package/docs/interfaces/ITweet.html +0 -176
  193. package/docs/interfaces/ITweetEntities.html +0 -104
  194. package/docs/interfaces/ITweetFilter.html +0 -158
  195. package/docs/interfaces/IUser.html +0 -194
  196. package/docs/modules.html +0 -111
  197. package/environment.d.ts +0 -11
  198. package/src/config/env.ts +0 -5
  199. package/src/enums/Errors.ts +0 -22
  200. package/src/graphql/enums/Errors.ts +0 -22
  201. package/src/graphql/queries/RootQuery.ts +0 -81
  202. package/src/graphql/resolvers/AccountResolver.ts +0 -22
  203. package/src/graphql/resolvers/ResolverBase.ts +0 -26
  204. package/src/graphql/resolvers/TweetResolver.ts +0 -225
  205. package/src/graphql/resolvers/UserResolver.ts +0 -257
  206. package/src/graphql/types/Global.ts +0 -10
  207. package/src/graphql/types/TweetTypes.ts +0 -158
  208. package/src/graphql/types/UserTypes.ts +0 -134
  209. package/src/models/args/TweetListArgs.ts +0 -47
  210. package/src/models/args/UserListArgs.ts +0 -47
  211. package/src/models/auth/AuthCookie.ts +0 -43
  212. package/src/models/data/CursoredData.ts +0 -45
  213. package/src/models/data/Tweet.ts +0 -118
  214. package/src/models/data/User.ts +0 -72
  215. package/src/server.ts +0 -37
  216. package/src/services/auth/AccountService.ts +0 -283
  217. package/src/services/auth/AuthService.ts +0 -81
  218. package/src/services/data/TweetService.ts +0 -197
  219. package/src/services/data/UserService.ts +0 -221
  220. package/src/services/helper/Headers.ts +0 -60
  221. package/src/services/helper/Parser.ts +0 -89
  222. package/src/services/helper/extractors/Tweets.ts +0 -190
  223. package/src/services/helper/extractors/Users.ts +0 -141
  224. package/src/services/helper/payloads/LoginFlows.ts +0 -90
  225. package/src/services/helper/urls/Authentication.ts +0 -6
  226. package/src/services/util/CacheService.ts +0 -76
  227. package/src/services/util/FetcherService.ts +0 -143
  228. package/src/types/Args.ts +0 -12
  229. package/src/types/Authentication.ts +0 -63
  230. package/src/types/Resolvers.ts +0 -18
  231. package/src/types/Rettiwt.ts +0 -20
  232. package/src/types/Service.ts +0 -24
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.UserService = void 0;
55
+ // PACKAGES
56
+ var rettiwt_core_1 = require("rettiwt-core");
57
+ // SERVICES
58
+ var FetcherService_1 = require("./FetcherService");
59
+ /**
60
+ * Handles fetching of data related to user account
61
+ *
62
+ * @public
63
+ */
64
+ var UserService = /** @class */ (function (_super) {
65
+ __extends(UserService, _super);
66
+ /**
67
+ * @param cred - The credentials to use for authenticating against Twitter API.
68
+ *
69
+ * @internal
70
+ */
71
+ function UserService(cred) {
72
+ return _super.call(this, cred) || this;
73
+ }
74
+ /**
75
+ * Get the details of a user.
76
+ *
77
+ * @param id - The username/id of the target user.
78
+ * @returns The details of the given user.
79
+ *
80
+ * @public
81
+ */
82
+ UserService.prototype.details = function (id) {
83
+ return __awaiter(this, void 0, void 0, function () {
84
+ var data;
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0:
88
+ if (!isNaN(parseFloat(id))) return [3 /*break*/, 2];
89
+ return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_DETAILS, { id: id })];
90
+ case 1:
91
+ // Fetching the requested data
92
+ data = _a.sent();
93
+ return [3 /*break*/, 4];
94
+ case 2: return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_DETAILS_BY_ID, { id: id })];
95
+ case 3:
96
+ // Fetching the requested data
97
+ data = _a.sent();
98
+ _a.label = 4;
99
+ case 4: return [2 /*return*/, data.list[0]];
100
+ }
101
+ });
102
+ });
103
+ };
104
+ /**
105
+ * Get the list of users who are followed by the given user.
106
+ *
107
+ * @param userId - The rest id of the target user.
108
+ * @param count - The number of following to fetch, must be \<= 100.
109
+ * @param cursor - The cursor to the batch of following to fetch.
110
+ * @returns The list of users followed by the target user.
111
+ *
112
+ * @public
113
+ */
114
+ UserService.prototype.following = function (userId, count, cursor) {
115
+ return __awaiter(this, void 0, void 0, function () {
116
+ var data;
117
+ return __generator(this, function (_a) {
118
+ switch (_a.label) {
119
+ case 0: return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_FOLLOWING, {
120
+ id: userId,
121
+ count: count,
122
+ cursor: cursor,
123
+ })];
124
+ case 1:
125
+ data = _a.sent();
126
+ return [2 /*return*/, data];
127
+ }
128
+ });
129
+ });
130
+ };
131
+ /**
132
+ * Get the list followers of a given user.
133
+ *
134
+ * @param userId - The rest id of the target user.
135
+ * @param count - The number of followers to fetch, must be \<= 100.
136
+ * @param cursor - The cursor to the batch of followers to fetch.
137
+ * @returns The list of users following the target user.
138
+ *
139
+ * @public
140
+ */
141
+ UserService.prototype.followers = function (userId, count, cursor) {
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ var data;
144
+ return __generator(this, function (_a) {
145
+ switch (_a.label) {
146
+ case 0: return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_FOLLOWERS, {
147
+ id: userId,
148
+ count: count,
149
+ cursor: cursor,
150
+ })];
151
+ case 1:
152
+ data = _a.sent();
153
+ return [2 /*return*/, data];
154
+ }
155
+ });
156
+ });
157
+ };
158
+ /**
159
+ * Get the list of tweets liked by the given user.
160
+ *
161
+ * @param userId - The rest id of the target user.
162
+ * @param count - The number of likes to fetch, must be \<= 100.
163
+ * @param cursor - The cursor to the batch of likes to fetch.
164
+ * @returns The list of tweets liked by the target user.
165
+ *
166
+ * @public
167
+ */
168
+ UserService.prototype.likes = function (userId, count, cursor) {
169
+ return __awaiter(this, void 0, void 0, function () {
170
+ var data;
171
+ return __generator(this, function (_a) {
172
+ switch (_a.label) {
173
+ case 0: return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_LIKES, {
174
+ id: userId,
175
+ count: count,
176
+ cursor: cursor,
177
+ })];
178
+ case 1:
179
+ data = _a.sent();
180
+ return [2 /*return*/, data];
181
+ }
182
+ });
183
+ });
184
+ };
185
+ return UserService;
186
+ }(FetcherService_1.FetcherService));
187
+ exports.UserService = UserService;
188
+ //# sourceMappingURL=UserService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserService.js","sourceRoot":"","sources":["../../src/services/UserService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,WAAW;AACX,6CAA6C;AAG7C,WAAW;AACX,mDAAkD;AASlD;;;;GAIG;AACH;IAAiC,+BAAc;IAC9C;;;;OAIG;IACH,qBAAY,IAAoB;eAC/B,kBAAM,IAAI,CAAC;IACZ,CAAC;IAED;;;;;;;OAOG;IACG,6BAAO,GAAb,UAAc,EAAU;;;;;;6BAInB,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,EAArB,wBAAqB;wBAEjB,qBAAM,IAAI,CAAC,KAAK,CAAO,4BAAa,CAAC,YAAY,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAA;;wBADrE,8BAA8B;wBAC9B,IAAI,GAAG,SAA8D,CAAC;;4BAK/D,qBAAM,IAAI,CAAC,KAAK,CAAO,4BAAa,CAAC,kBAAkB,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAA;;wBAD3E,8BAA8B;wBAC9B,IAAI,GAAG,SAAoE,CAAC;;4BAG7E,sBAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAC;;;;KACpB;IAED;;;;;;;;;OASG;IACG,+BAAS,GAAf,UAAgB,MAAc,EAAE,KAAc,EAAE,MAAe;;;;;4BAEjD,qBAAM,IAAI,CAAC,KAAK,CAAO,4BAAa,CAAC,cAAc,EAAE;4BACjE,EAAE,EAAE,MAAM;4BACV,KAAK,EAAE,KAAK;4BACZ,MAAM,EAAE,MAAM;yBACd,CAAC,EAAA;;wBAJI,IAAI,GAAG,SAIX;wBAEF,sBAAO,IAAI,EAAC;;;;KACZ;IAED;;;;;;;;;OASG;IACG,+BAAS,GAAf,UAAgB,MAAc,EAAE,KAAc,EAAE,MAAe;;;;;4BAEjD,qBAAM,IAAI,CAAC,KAAK,CAAO,4BAAa,CAAC,cAAc,EAAE;4BACjE,EAAE,EAAE,MAAM;4BACV,KAAK,EAAE,KAAK;4BACZ,MAAM,EAAE,MAAM;yBACd,CAAC,EAAA;;wBAJI,IAAI,GAAG,SAIX;wBAEF,sBAAO,IAAI,EAAC;;;;KACZ;IAED;;;;;;;;;OASG;IACG,2BAAK,GAAX,UAAY,MAAc,EAAE,KAAc,EAAE,MAAe;;;;;4BAE7C,qBAAM,IAAI,CAAC,KAAK,CAAQ,4BAAa,CAAC,UAAU,EAAE;4BAC9D,EAAE,EAAE,MAAM;4BACV,KAAK,EAAE,KAAK;4BACZ,MAAM,EAAE,MAAM;yBACd,CAAC,EAAA;;wBAJI,IAAI,GAAG,SAIX;wBAEF,sBAAO,IAAI,EAAC;;;;KACZ;IACF,kBAAC;AAAD,CAAC,AAjGD,CAAiC,+BAAc,GAiG9C;AAjGY,kCAAW"}
@@ -10,13 +10,13 @@ export interface ICursor {
10
10
  /**
11
11
  * The data that us fetched batch-wise along with a cursor.
12
12
  *
13
- * @typeParam Type - The type of data present in the list.
13
+ * @typeParam T - Type of data present in the list.
14
14
  *
15
15
  * @public
16
16
  */
17
- export interface ICursoredData<Type> {
17
+ export interface ICursoredData<T> {
18
18
  /** The list of data of the given type. */
19
- list: Type[];
19
+ list: T[];
20
20
  /** The cursor to the next batch of data. */
21
21
  next: ICursor;
22
22
  }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=CursoredData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CursoredData.js","sourceRoot":"","sources":["../../src/types/CursoredData.ts"],"names":[],"mappings":""}
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=Tweet.js.map
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=User.js.map
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "rettiwt-api",
3
- "version": "1.4.0",
3
+ "version": "2.0.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "An API for fetching data from TwitterAPI, without any rate limits!",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "start": "node ./dist/server.js",
10
- "debug": "nodemon ./dist/server.js --inspect=0.0.0.0:9229"
9
+ "format": "prettier --write .",
10
+ "lint": "eslint --max-warnings 0 .",
11
+ "docs": "typedoc src/index.ts",
12
+ "debug": "nodemon ./dist/index.js --inspect=0.0.0.0:9229"
11
13
  },
12
14
  "repository": {
13
15
  "type": "git",
@@ -24,24 +26,18 @@
24
26
  "homepage": "https://rishikant181.github.io/Rettiwt-API/",
25
27
  "dependencies": {
26
28
  "axios": "1.3.2",
27
- "class-transformer": "0.5.1",
28
- "class-validator": "0.14.0",
29
- "cookiejar": "2.1.4",
30
- "express": "4.18.2",
31
- "express-graphql": "0.12.0",
32
- "graphql": "14.7.0",
33
- "node-cache": "5.1.2",
34
- "node-libcurl": "3.0.0",
35
- "reflect-metadata": "0.1.13",
36
- "rettiwt-core": "2.4.0"
29
+ "rettiwt-auth": "1.2.0",
30
+ "rettiwt-core": "3.0.0"
37
31
  },
38
32
  "devDependencies": {
39
- "@types/cookiejar": "2.1.2",
40
- "@types/express": "4.17.13",
41
- "@types/graphql": "14.5.0",
42
- "@types/node": "17.0.24",
33
+ "@types/node": "20.4.1",
34
+ "@typescript-eslint/eslint-plugin": "6.0.0",
35
+ "@typescript-eslint/parser": "6.0.0",
36
+ "eslint": "8.44.0",
37
+ "eslint-plugin-tsdoc": "0.2.17",
43
38
  "nodemon": "2.0.20",
44
- "typedoc": "0.23.26",
45
- "typescript": "4.6.4"
39
+ "prettier": "3.0.0",
40
+ "typedoc": "0.24.8",
41
+ "typescript": "5.1.6"
46
42
  }
47
43
  }
package/src/Rettiwt.ts ADDED
@@ -0,0 +1,33 @@
1
+ // PACKAGE
2
+ import { AuthCredential } from 'rettiwt-auth';
3
+
4
+ // SERVICES
5
+ import { TweetService } from './services/TweetService';
6
+ import { UserService } from './services/UserService';
7
+
8
+ /**
9
+ * The class for fetching data from Twitter.
10
+ *
11
+ * @public
12
+ */
13
+ export class Rettiwt {
14
+ /** The instance used to fetch data related to tweets. */
15
+ tweet: TweetService;
16
+
17
+ /** The instance used to fetch data related to users. */
18
+ user: UserService;
19
+
20
+ /**
21
+ * Initializes a new Rettiwt instance using the given api key.
22
+ *
23
+ * @param apiKey - The apiKey (cookie) to be used for authenticating Rettiwt against Twitter.
24
+ */
25
+ constructor(apiKey: string) {
26
+ // Preparing auth credentials
27
+ const cred: AuthCredential = new AuthCredential(apiKey.split(';'));
28
+
29
+ // Initalizing service instances
30
+ this.tweet = new TweetService(cred);
31
+ this.user = new UserService(cred);
32
+ }
33
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The different types of api error messages.
3
+ *
4
+ * @public
5
+ */
6
+ export enum EApiErrors {
7
+ COULD_NOT_AUTHENTICATE = 'Failed to authenticate',
8
+ RESOURCE_NOT_FOUND = 'Requested resource not found',
9
+ MISSING_PARAMETER = 'Missing named parameter',
10
+ USER_NOT_FOUND = 'Requested user not found',
11
+ USER_SUSPENDED = 'Requested user has been suspended',
12
+ ACCOUNT_SUSPENDED = 'Account has been suspended',
13
+ RATE_LIMIT_EXCEEDED = 'Rate limit exceeded',
14
+ INTERNAL_ERROR = 'Internal server error',
15
+ TIME_ERROR = 'Mismatched data/time with server',
16
+ ALREADY_FAVORITED = 'Tweet already favorited',
17
+ STATUS_NOT_FOUND = 'Requested tweeet not found',
18
+ NOT_AUTHORIZED = 'Not authorized to view tweet',
19
+ DAILY_STATUS_LIMIT_EXCEEDED = 'Exceeded daily tweet update limit',
20
+ TWEET_LENGTH_EXCEEDED = 'Exceeded tweet text maximum length',
21
+ DUPLICATE_STATUS = 'Tweet already posted',
22
+ BAD_AUTHENTICATION = 'Invalid authentication data',
23
+ RESOURCE_NOT_ALLOWED = 'Not authorized to access requested resource',
24
+ AUTOMATED_REQUEST_ERROR = 'Automated request detected',
25
+ ACCOUNT_LOCKED = 'Account has been locked',
26
+ ALREADY_RETWEETED = 'Tweet already retweeted',
27
+ TWEET_NOT_FOUND = 'Requested tweet not found',
28
+ TWEET_VIOLATED_RULES = 'Requestd tweet has been removed for rules violation',
29
+ DISABLED_TWEET_ACTIONS = 'Reqeusted action disabled on the tweet',
30
+ }
package/src/enums/HTTP.ts CHANGED
@@ -3,15 +3,15 @@
3
3
  *
4
4
  * @internal
5
5
  */
6
- export enum HttpStatus {
7
- BadRequest = 400,
8
- Unauthorized = 401,
9
- Forbidden = 403,
10
- NotFound = 404,
11
- MethodNotAllowed = 405,
12
- RequestTimeout = 408,
13
- TooManyRequests = 429,
14
- InternalServerError = 500,
15
- BadGateway = 502,
16
- ServiceUnavailable = 503
17
- };
6
+ export enum EHttpStatus {
7
+ BAD_REQUEST = 400,
8
+ UNAUTHORIZED = 401,
9
+ FORBIDDEN = 403,
10
+ NOT_FOUND = 404,
11
+ METHOD_NOT_ALLOWED = 405,
12
+ REQUEST_TIMEOUT = 408,
13
+ TOO_MANY_REQUESTS = 429,
14
+ INTERNAL_SERVER_ERROR = 500,
15
+ BAD_GATEWAY = 502,
16
+ SERVICE_UNAVAILABLE = 503,
17
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Search for all the sub-objects (even deep-nested ones) that have the given key-value pair(filter).
3
+ *
4
+ * @param data - The data on which search is to be performed.
5
+ * @param key - The key of the key-value pair to search.
6
+ * @param value - The value of the key-value pait to search.
7
+ * @returns The list of sub-objects from the given object, having the given key-value pair.
8
+ *
9
+ * @internal
10
+ */
11
+ export function findByFilter<T>(data: NonNullable<unknown>, key: string, value: string): T[] {
12
+ /**
13
+ * The list containing all the objects matching given filter.
14
+ */
15
+ let res: T[] = [];
16
+
17
+ /**
18
+ * If the data is an array, recursively run the function of each element of the array and merge the results.
19
+ */
20
+ if (Array.isArray(data)) {
21
+ /**
22
+ * findByFilter returns an array.
23
+ * map() also returns an array.
24
+ * Therefore, map(item =\> findByFilter(.......)) returns an array of arrays.
25
+ * Therefore, using ... operator to spread the 2-D array in 1-D array.
26
+ */
27
+ res = res.concat(...data.map((item) => findByFilter<T>(item as NonNullable<unknown>, key, value)));
28
+ }
29
+ // If the data is an object
30
+ else if (typeof data == 'object') {
31
+ /**
32
+ * If the object includes the key and the value specified by the key matches the filter, add it to the result.
33
+ */
34
+ if (Object.keys(data).includes(key) && data[key as keyof typeof data] == value) {
35
+ res.push(data as T);
36
+ }
37
+
38
+ /**
39
+ * Recursively run the function on each value specified by each key in the object, for subsequent matches.
40
+ */
41
+ for (const [, v] of Object.entries(data)) {
42
+ res = res.concat(findByFilter<T>(v as NonNullable<unknown>, key, value));
43
+ }
44
+ }
45
+
46
+ return res;
47
+ }
48
+
49
+ /**
50
+ * @param text - The text to be normalized.
51
+ * @returns The text after being formatted to remove unnecessary characters.
52
+ *
53
+ * @internal
54
+ */
55
+ export function normalizeText(text: string): string {
56
+ let normalizedText: string = ''; // To store the normalized text
57
+
58
+ // Removing unnecessary full stops, and other characters
59
+ normalizedText = text.replace(/\n/g, '.').replace(/[.]+[\s+.\s+]+/g, '. ');
60
+
61
+ // Adding full-stop to the end if does not exist already
62
+ normalizedText = normalizedText.endsWith('.') ? normalizedText : normalizedText + '.';
63
+
64
+ return normalizedText;
65
+ }
66
+
67
+ /**
68
+ * Searches for the key which has the given value in the given object.
69
+ *
70
+ * @param data - The data on which search is to be performed.
71
+ * @param value - The value to search.
72
+ * @returns The key with the given value.
73
+ */
74
+ export function findKeyByValue(data: NonNullable<unknown>, value: string): string | undefined {
75
+ // Finding the key-value pairs that have the given value
76
+ const kvPair = Object.entries(data).filter(([, v]) => v == value)[0];
77
+
78
+ // If a match is found
79
+ if (kvPair) {
80
+ return kvPair[0];
81
+ }
82
+ // If no match is found
83
+ else {
84
+ return undefined;
85
+ }
86
+ }
package/src/index.ts CHANGED
@@ -1,64 +1,21 @@
1
- // PACKAGES
2
- import 'reflect-metadata';
1
+ // MAIN
2
+ export * from './Rettiwt';
3
3
 
4
- // SERVICES
5
- import { AuthService } from "./services/auth/AuthService";
6
- import { UserService } from "./services/data/UserService";
7
- import { TweetService } from "./services/data/TweetService";
8
- import { AccountService } from "./services/auth/AccountService";
4
+ // Exporting enums
5
+ export * from './enums/ApiErrors';
6
+ export * from './enums/HTTP';
9
7
 
10
- // TYPES
11
- import { IAuthCookie } from './types/Authentication';
12
-
13
- /**
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
- *
22
- * @remarks The cookie can be obtained by using {@link AccountService.login} method.
23
- * To use the {@link AccountService.login} method, create a {@link Rettiwt} instance without passing any cookie .
24
- * Then use the {@link AccountService.login} method of {@link AccountService} to get the cookie.
25
- */
26
- export const Rettiwt = (cookie?: IAuthCookie) => {
27
- // Creating new auth service instance using the given cookie
28
- const auth: AuthService = new AuthService(cookie);
29
-
30
- // Using the auth service instance to create data services instances
31
- return {
32
- users: new UserService(auth),
33
- tweets: new TweetService(auth),
34
- account: new AccountService()
35
- };
36
- }
8
+ // Exporting models
9
+ export * from './models/CursoredData';
10
+ export * from './models/Tweet';
11
+ export * from './models/User';
37
12
 
38
- // Exporting classes
39
- export * from './services/auth/AuthService';
40
- export * from './services/auth/AccountService';
41
- export * from './services/data/TweetService';
42
- export * from './services/data/UserService';
43
- export * from './services/util/CacheService';
44
- export * from './services/util/FetcherService';
13
+ // Exporting services
14
+ export * from './services/FetcherService';
15
+ export * from './services/TweetService';
16
+ export * from './services/UserService';
45
17
 
46
18
  // Exporting types
47
- export { ITweetFilter } from 'rettiwt-core';
48
- export * from './types/Args';
49
- export { IAuthCookie } from './types/Authentication';
50
- export * from './types/Rettiwt';
51
- export * from './types/Service';
19
+ export * from './types/CursoredData';
52
20
  export * from './types/Tweet';
53
21
  export * from './types/User';
54
- export { IDataValidationError } from 'rettiwt-core';
55
-
56
- // Exporting models
57
- export { TweetFilter } from 'rettiwt-core';
58
- export * from './models/args/TweetListArgs';
59
- export * from './models/args/UserListArgs';
60
- export { AuthCookie } from './models/auth/AuthCookie';
61
- export * from './models/data/CursoredData';
62
- export * from './models/data/Tweet';
63
- export * from './models/data/User';
64
- export { DataValidationError } from 'rettiwt-core';
@@ -0,0 +1,64 @@
1
+ // PACKAGES
2
+ import { ITweet as IRawTweet, IUser as IRawUser } from 'rettiwt-core';
3
+
4
+ // MODELS
5
+ import { Tweet } from './Tweet';
6
+ import { User } from './User';
7
+
8
+ // TYPES
9
+ import { ICursor, ICursoredData } from '../types/CursoredData';
10
+
11
+ /**
12
+ * The cursor to the batch of data to be fetched.
13
+ *
14
+ * @public
15
+ */
16
+ export class Cursor implements ICursor {
17
+ /** The cursor string. */
18
+ value: string;
19
+
20
+ /**
21
+ * Initializes a new cursor from the given cursor string.
22
+ *
23
+ * @param cursorStr - The string representation of the cursor.
24
+ */
25
+ constructor(cursorStr: string) {
26
+ this.value = cursorStr;
27
+ }
28
+ }
29
+
30
+ /**
31
+ * The data that us fetched batch-wise along with a cursor.
32
+ *
33
+ * @typeParam T - Type of data to be stored in the list.
34
+ *
35
+ * @public
36
+ */
37
+ export class CursoredData<T extends Tweet | User> implements ICursoredData<T> {
38
+ /** The list of data of the given type. */
39
+ list: T[] = [];
40
+
41
+ /** The cursor to the next batch of data. */
42
+ next: Cursor;
43
+
44
+ /**
45
+ * @param list - The list of data item to store.
46
+ * @param next - The cursor to the next batch of data.
47
+ */
48
+ constructor(list: (IRawTweet | IRawUser)[] = [], next: string = '') {
49
+ // Deserializing the input raw data and storing it in the list
50
+ for (const item of list) {
51
+ // If the item is a valid raw tweet
52
+ if (item.__typename == 'Tweet' && item.rest_id) {
53
+ this.list.push(new Tweet(item as IRawTweet) as T);
54
+ }
55
+ // If the item is a valid raw user
56
+ else if (item.__typename == 'User' && item.rest_id) {
57
+ this.list.push(new User(item as IRawUser) as T);
58
+ }
59
+ }
60
+
61
+ // Initializing cursors
62
+ this.next = new Cursor(next);
63
+ }
64
+ }