rettiwt-api 4.2.0 → 5.0.0-alpha.1

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 (179) hide show
  1. package/.eslintrc.js +2 -3
  2. package/.github/workflows/documentation.yml +1 -1
  3. package/.github/workflows/publish-alpha.yml +1 -1
  4. package/.github/workflows/publish.yml +1 -1
  5. package/.prettierignore +1 -1
  6. package/.tool-versions +1 -1
  7. package/README.md +100 -100
  8. package/dist/Rettiwt.d.ts +1 -1
  9. package/dist/Rettiwt.js +15 -8
  10. package/dist/Rettiwt.js.map +1 -1
  11. package/dist/cli.js +8 -11
  12. package/dist/cli.js.map +1 -1
  13. package/dist/collections/Extractors.d.ts +1 -0
  14. package/dist/collections/Extractors.js +38 -69
  15. package/dist/collections/Extractors.js.map +1 -1
  16. package/dist/collections/Groups.js +2 -1
  17. package/dist/collections/Groups.js.map +1 -1
  18. package/dist/collections/Requests.d.ts +3 -3
  19. package/dist/collections/Requests.js +36 -35
  20. package/dist/collections/Requests.js.map +1 -1
  21. package/dist/commands/List.js +21 -78
  22. package/dist/commands/List.js.map +1 -1
  23. package/dist/commands/Tweet.js +185 -370
  24. package/dist/commands/Tweet.js.map +1 -1
  25. package/dist/commands/User.js +129 -306
  26. package/dist/commands/User.js.map +1 -1
  27. package/dist/enums/Authentication.d.ts +18 -0
  28. package/dist/enums/Authentication.js +24 -0
  29. package/dist/enums/Authentication.js.map +1 -0
  30. package/dist/enums/Data.d.ts +12 -0
  31. package/dist/enums/Data.js +14 -1
  32. package/dist/enums/Data.js.map +1 -1
  33. package/dist/enums/Resource.d.ts +1 -0
  34. package/dist/enums/Resource.js +1 -0
  35. package/dist/enums/Resource.js.map +1 -1
  36. package/dist/helper/CliUtils.js +1 -2
  37. package/dist/helper/CliUtils.js.map +1 -1
  38. package/dist/helper/JsonUtils.js +6 -11
  39. package/dist/helper/JsonUtils.js.map +1 -1
  40. package/dist/index.d.ts +1 -2
  41. package/dist/index.js +1 -2
  42. package/dist/index.js.map +1 -1
  43. package/dist/models/args/FetchArgs.d.ts +4 -133
  44. package/dist/models/args/FetchArgs.js +12 -416
  45. package/dist/models/args/FetchArgs.js.map +1 -1
  46. package/dist/models/args/PostArgs.d.ts +16 -101
  47. package/dist/models/args/PostArgs.js +26 -258
  48. package/dist/models/args/PostArgs.js.map +1 -1
  49. package/dist/models/auth/AccountCredential.d.ts +13 -0
  50. package/dist/models/auth/AccountCredential.js +21 -0
  51. package/dist/models/auth/AccountCredential.js.map +1 -0
  52. package/dist/models/auth/AuthCookie.d.ts +19 -0
  53. package/dist/models/auth/AuthCookie.js +53 -0
  54. package/dist/models/auth/AuthCookie.js.map +1 -0
  55. package/dist/models/auth/AuthCredential.d.ts +28 -0
  56. package/dist/models/auth/AuthCredential.js +76 -0
  57. package/dist/models/auth/AuthCredential.js.map +1 -0
  58. package/dist/models/data/CursoredData.d.ts +3 -4
  59. package/dist/models/data/CursoredData.js +19 -19
  60. package/dist/models/data/CursoredData.js.map +1 -1
  61. package/dist/models/data/List.d.ts +2 -8
  62. package/dist/models/data/List.js +10 -4
  63. package/dist/models/data/List.js.map +1 -1
  64. package/dist/models/data/Notification.d.ts +5 -21
  65. package/dist/models/data/Notification.js +24 -33
  66. package/dist/models/data/Notification.js.map +1 -1
  67. package/dist/models/data/Tweet.d.ts +4 -17
  68. package/dist/models/data/Tweet.js +83 -73
  69. package/dist/models/data/Tweet.js.map +1 -1
  70. package/dist/models/data/User.d.ts +2 -15
  71. package/dist/models/data/User.js +33 -23
  72. package/dist/models/data/User.js.map +1 -1
  73. package/dist/models/errors/ApiError.js +8 -24
  74. package/dist/models/errors/ApiError.js.map +1 -1
  75. package/dist/models/errors/HttpError.js +8 -24
  76. package/dist/models/errors/HttpError.js.map +1 -1
  77. package/dist/models/errors/RettiwtError.js +5 -23
  78. package/dist/models/errors/RettiwtError.js.map +1 -1
  79. package/dist/models/errors/TimeoutError.js +5 -22
  80. package/dist/models/errors/TimeoutError.js.map +1 -1
  81. package/dist/services/{public → internal}/AuthService.d.ts +5 -34
  82. package/dist/services/internal/AuthService.js +109 -0
  83. package/dist/services/internal/AuthService.js.map +1 -0
  84. package/dist/services/internal/ErrorService.js +38 -40
  85. package/dist/services/internal/ErrorService.js.map +1 -1
  86. package/dist/services/internal/LogService.d.ts +0 -6
  87. package/dist/services/internal/LogService.js +12 -32
  88. package/dist/services/internal/LogService.js.map +1 -1
  89. package/dist/services/public/FetcherService.d.ts +5 -3
  90. package/dist/services/public/FetcherService.js +96 -141
  91. package/dist/services/public/FetcherService.js.map +1 -1
  92. package/dist/services/public/ListService.js +31 -100
  93. package/dist/services/public/ListService.js.map +1 -1
  94. package/dist/services/public/TweetService.d.ts +29 -4
  95. package/dist/services/public/TweetService.js +208 -386
  96. package/dist/services/public/TweetService.js.map +1 -1
  97. package/dist/services/public/UserService.js +186 -385
  98. package/dist/services/public/UserService.js.map +1 -1
  99. package/dist/types/RettiwtConfig.d.ts +8 -0
  100. package/dist/types/args/FetchArgs.d.ts +59 -0
  101. package/dist/types/args/FetchArgs.js +3 -0
  102. package/dist/types/args/FetchArgs.js.map +1 -0
  103. package/dist/types/args/PostArgs.d.ts +56 -0
  104. package/dist/types/args/PostArgs.js +3 -0
  105. package/dist/types/args/PostArgs.js.map +1 -0
  106. package/dist/types/auth/AccountCredential.d.ts +11 -0
  107. package/dist/types/auth/AccountCredential.js +3 -0
  108. package/dist/types/auth/AccountCredential.js.map +1 -0
  109. package/dist/types/auth/AuthCookie.d.ts +13 -0
  110. package/dist/types/auth/AuthCookie.js +3 -0
  111. package/dist/types/auth/AuthCookie.js.map +1 -0
  112. package/dist/types/auth/AuthCredential.d.ts +21 -0
  113. package/dist/types/auth/AuthCredential.js +3 -0
  114. package/dist/types/auth/AuthCredential.js.map +1 -0
  115. package/dist/types/data/CursoredData.d.ts +25 -0
  116. package/dist/types/data/CursoredData.js +3 -0
  117. package/dist/types/data/CursoredData.js.map +1 -0
  118. package/dist/types/data/List.d.ts +21 -0
  119. package/dist/types/data/List.js +3 -0
  120. package/dist/types/data/List.js.map +1 -0
  121. package/dist/types/data/Notification.d.ts +20 -0
  122. package/dist/types/data/Notification.js +3 -0
  123. package/dist/types/data/Notification.js.map +1 -0
  124. package/dist/types/data/Tweet.d.ts +71 -0
  125. package/dist/types/data/Tweet.js +3 -0
  126. package/dist/types/data/Tweet.js.map +1 -0
  127. package/dist/types/data/User.d.ts +35 -0
  128. package/dist/types/data/User.js +3 -0
  129. package/dist/types/data/User.js.map +1 -0
  130. package/eslint.config.mjs +17 -0
  131. package/package.json +22 -19
  132. package/src/Rettiwt.ts +1 -1
  133. package/src/cli.ts +0 -2
  134. package/src/collections/Extractors.ts +2 -0
  135. package/src/collections/Groups.ts +1 -0
  136. package/src/collections/Requests.ts +37 -36
  137. package/src/enums/Authentication.ts +19 -0
  138. package/src/enums/Data.ts +13 -0
  139. package/src/enums/Resource.ts +1 -0
  140. package/src/helper/JsonUtils.ts +1 -1
  141. package/src/index.ts +1 -2
  142. package/src/models/args/FetchArgs.ts +4 -470
  143. package/src/models/args/PostArgs.ts +20 -285
  144. package/src/models/auth/AccountCredential.ts +19 -0
  145. package/src/models/auth/AuthCookie.ts +56 -0
  146. package/src/models/auth/AuthCredential.ts +83 -0
  147. package/src/models/data/CursoredData.ts +12 -9
  148. package/src/models/data/List.ts +3 -14
  149. package/src/models/data/Notification.ts +6 -28
  150. package/src/models/data/Tweet.ts +17 -43
  151. package/src/models/data/User.ts +5 -31
  152. package/src/services/{public → internal}/AuthService.ts +28 -55
  153. package/src/services/internal/LogService.ts +4 -19
  154. package/src/services/public/FetcherService.ts +18 -8
  155. package/src/services/public/TweetService.ts +44 -4
  156. package/src/services/public/UserService.ts +2 -2
  157. package/src/types/RettiwtConfig.ts +7 -0
  158. package/src/types/args/FetchArgs.ts +64 -0
  159. package/src/types/args/PostArgs.ts +62 -0
  160. package/src/types/auth/AccountCredential.ts +13 -0
  161. package/src/types/auth/AuthCookie.ts +20 -0
  162. package/src/types/auth/AuthCredential.ts +26 -0
  163. package/src/types/data/CursoredData.ts +28 -0
  164. package/src/types/data/List.ts +27 -0
  165. package/src/types/data/Notification.ts +26 -0
  166. package/src/types/data/Tweet.ts +96 -0
  167. package/src/types/data/User.ts +48 -0
  168. package/tsconfig.json +7 -5
  169. package/.eslintignore +0 -3
  170. package/dist/commands/Auth.d.ts +0 -10
  171. package/dist/commands/Auth.js +0 -101
  172. package/dist/commands/Auth.js.map +0 -1
  173. package/dist/models/errors/DataValidationError.d.ts +0 -30
  174. package/dist/models/errors/DataValidationError.js +0 -34
  175. package/dist/models/errors/DataValidationError.js.map +0 -1
  176. package/dist/services/public/AuthService.js +0 -205
  177. package/dist/services/public/AuthService.js.map +0 -1
  178. package/src/commands/Auth.ts +0 -46
  179. package/src/models/errors/DataValidationError.ts +0 -44
@@ -1,86 +1,22 @@
1
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
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
54
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
55
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
56
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
57
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
58
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
59
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
60
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
61
- function fulfill(value) { resume("next", value); }
62
- function reject(value) { resume("throw", value); }
63
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
64
- };
65
2
  Object.defineProperty(exports, "__esModule", { value: true });
66
3
  exports.UserService = void 0;
67
- var Extractors_1 = require("../../collections/Extractors");
68
- var Resource_1 = require("../../enums/Resource");
69
- var FetcherService_1 = require("./FetcherService");
4
+ const Extractors_1 = require("../../collections/Extractors");
5
+ const Resource_1 = require("../../enums/Resource");
6
+ const FetcherService_1 = require("./FetcherService");
70
7
  /**
71
8
  * Handles interacting with resources related to user account
72
9
  *
73
10
  * @public
74
11
  */
75
- var UserService = /** @class */ (function (_super) {
76
- __extends(UserService, _super);
12
+ class UserService extends FetcherService_1.FetcherService {
77
13
  /**
78
14
  * @param config - The config object for configuring the Rettiwt instance.
79
15
  *
80
16
  * @internal
81
17
  */
82
- function UserService(config) {
83
- return _super.call(this, config) || this;
18
+ constructor(config) {
19
+ super(config);
84
20
  }
85
21
  /**
86
22
  * Get the list of bookmarks of the logged in user.
@@ -107,25 +43,17 @@ var UserService = /** @class */ (function (_super) {
107
43
  * });
108
44
  * ```
109
45
  */
110
- UserService.prototype.bookmarks = function (count, cursor) {
111
- return __awaiter(this, void 0, void 0, function () {
112
- var resource, response, data;
113
- return __generator(this, function (_a) {
114
- switch (_a.label) {
115
- case 0:
116
- resource = Resource_1.EResourceType.USER_BOOKMARKS;
117
- return [4 /*yield*/, this.request(resource, {
118
- count: count,
119
- cursor: cursor,
120
- })];
121
- case 1:
122
- response = _a.sent();
123
- data = Extractors_1.extractors[resource](response);
124
- return [2 /*return*/, data];
125
- }
126
- });
46
+ async bookmarks(count, cursor) {
47
+ const resource = Resource_1.EResourceType.USER_BOOKMARKS;
48
+ // Fetching raw list of likes
49
+ const response = await this.request(resource, {
50
+ count: count,
51
+ cursor: cursor,
127
52
  });
128
- };
53
+ // Deserializing response
54
+ const data = Extractors_1.extractors[resource](response);
55
+ return data;
56
+ }
129
57
  /**
130
58
  * Get the details of a user.
131
59
  *
@@ -171,29 +99,22 @@ var UserService = /** @class */ (function (_super) {
171
99
  * });
172
100
  * ```
173
101
  */
174
- UserService.prototype.details = function (id) {
175
- return __awaiter(this, void 0, void 0, function () {
176
- var resource, response, data;
177
- return __generator(this, function (_a) {
178
- switch (_a.label) {
179
- case 0:
180
- // If username is given
181
- if (isNaN(Number(id))) {
182
- resource = Resource_1.EResourceType.USER_DETAILS_BY_USERNAME;
183
- }
184
- // If id is given
185
- else {
186
- resource = Resource_1.EResourceType.USER_DETAILS_BY_ID;
187
- }
188
- return [4 /*yield*/, this.request(resource, { id: id })];
189
- case 1:
190
- response = _a.sent();
191
- data = Extractors_1.extractors[resource](response);
192
- return [2 /*return*/, data];
193
- }
194
- });
195
- });
196
- };
102
+ async details(id) {
103
+ let resource;
104
+ // If username is given
105
+ if (isNaN(Number(id))) {
106
+ resource = Resource_1.EResourceType.USER_DETAILS_BY_USERNAME;
107
+ }
108
+ // If id is given
109
+ else {
110
+ resource = Resource_1.EResourceType.USER_DETAILS_BY_ID;
111
+ }
112
+ // Fetching raw details
113
+ const response = await this.request(resource, { id: id });
114
+ // Deserializing response
115
+ const data = Extractors_1.extractors[resource](response);
116
+ return data;
117
+ }
197
118
  /**
198
119
  * Follow a user.
199
120
  *
@@ -220,23 +141,14 @@ var UserService = /** @class */ (function (_super) {
220
141
  * });
221
142
  * ```
222
143
  */
223
- UserService.prototype.follow = function (id) {
224
- var _a;
225
- return __awaiter(this, void 0, void 0, function () {
226
- var resource, response, data;
227
- return __generator(this, function (_b) {
228
- switch (_b.label) {
229
- case 0:
230
- resource = Resource_1.EResourceType.USER_FOLLOW;
231
- return [4 /*yield*/, this.request(Resource_1.EResourceType.USER_FOLLOW, { id: id })];
232
- case 1:
233
- response = _b.sent();
234
- data = (_a = Extractors_1.extractors[resource](response)) !== null && _a !== void 0 ? _a : false;
235
- return [2 /*return*/, data];
236
- }
237
- });
238
- });
239
- };
144
+ async follow(id) {
145
+ const resource = Resource_1.EResourceType.USER_FOLLOW;
146
+ // Following the user
147
+ const response = await this.request(Resource_1.EResourceType.USER_FOLLOW, { id: id });
148
+ // Deserializing the response
149
+ const data = Extractors_1.extractors[resource](response) ?? false;
150
+ return data;
151
+ }
240
152
  /**
241
153
  * Get the followed feed of the logged in user.
242
154
  *
@@ -263,24 +175,16 @@ var UserService = /** @class */ (function (_super) {
263
175
  *
264
176
  * @remarks Always returns 35 feed items, with no way to customize the count.
265
177
  */
266
- UserService.prototype.followed = function (cursor) {
267
- return __awaiter(this, void 0, void 0, function () {
268
- var resource, response, data;
269
- return __generator(this, function (_a) {
270
- switch (_a.label) {
271
- case 0:
272
- resource = Resource_1.EResourceType.USER_FEED_FOLLOWED;
273
- return [4 /*yield*/, this.request(resource, {
274
- cursor: cursor,
275
- })];
276
- case 1:
277
- response = _a.sent();
278
- data = Extractors_1.extractors[resource](response);
279
- return [2 /*return*/, data];
280
- }
281
- });
178
+ async followed(cursor) {
179
+ const resource = Resource_1.EResourceType.USER_FEED_FOLLOWED;
180
+ // Fetching raw list of tweets
181
+ const response = await this.request(resource, {
182
+ cursor: cursor,
282
183
  });
283
- };
184
+ // Deserializing response
185
+ const data = Extractors_1.extractors[resource](response);
186
+ return data;
187
+ }
284
188
  /**
285
189
  * Get the list followers of a user.
286
190
  *
@@ -307,26 +211,18 @@ var UserService = /** @class */ (function (_super) {
307
211
  * });
308
212
  * ```
309
213
  */
310
- UserService.prototype.followers = function (id, count, cursor) {
311
- return __awaiter(this, void 0, void 0, function () {
312
- var resource, response, data;
313
- return __generator(this, function (_a) {
314
- switch (_a.label) {
315
- case 0:
316
- resource = Resource_1.EResourceType.USER_FOLLOWERS;
317
- return [4 /*yield*/, this.request(resource, {
318
- id: id,
319
- count: count,
320
- cursor: cursor,
321
- })];
322
- case 1:
323
- response = _a.sent();
324
- data = Extractors_1.extractors[resource](response);
325
- return [2 /*return*/, data];
326
- }
327
- });
214
+ async followers(id, count, cursor) {
215
+ const resource = Resource_1.EResourceType.USER_FOLLOWERS;
216
+ // Fetching raw list of followers
217
+ const response = await this.request(resource, {
218
+ id: id,
219
+ count: count,
220
+ cursor: cursor,
328
221
  });
329
- };
222
+ // Deserializing response
223
+ const data = Extractors_1.extractors[resource](response);
224
+ return data;
225
+ }
330
226
  /**
331
227
  * Get the list of users who are followed by a user.
332
228
  *
@@ -353,26 +249,18 @@ var UserService = /** @class */ (function (_super) {
353
249
  * });
354
250
  * ```
355
251
  */
356
- UserService.prototype.following = function (id, count, cursor) {
357
- return __awaiter(this, void 0, void 0, function () {
358
- var resource, response, data;
359
- return __generator(this, function (_a) {
360
- switch (_a.label) {
361
- case 0:
362
- resource = Resource_1.EResourceType.USER_FOLLOWING;
363
- return [4 /*yield*/, this.request(resource, {
364
- id: id,
365
- count: count,
366
- cursor: cursor,
367
- })];
368
- case 1:
369
- response = _a.sent();
370
- data = Extractors_1.extractors[resource](response);
371
- return [2 /*return*/, data];
372
- }
373
- });
252
+ async following(id, count, cursor) {
253
+ const resource = Resource_1.EResourceType.USER_FOLLOWING;
254
+ // Fetching raw list of following
255
+ const response = await this.request(resource, {
256
+ id: id,
257
+ count: count,
258
+ cursor: cursor,
374
259
  });
375
- };
260
+ // Deserializing response
261
+ const data = Extractors_1.extractors[resource](response);
262
+ return data;
263
+ }
376
264
  /**
377
265
  * Get the highlighted tweets of a user.
378
266
  *
@@ -399,26 +287,18 @@ var UserService = /** @class */ (function (_super) {
399
287
  * });
400
288
  * ```
401
289
  */
402
- UserService.prototype.highlights = function (id, count, cursor) {
403
- return __awaiter(this, void 0, void 0, function () {
404
- var resource, response, data;
405
- return __generator(this, function (_a) {
406
- switch (_a.label) {
407
- case 0:
408
- resource = Resource_1.EResourceType.USER_HIGHLIGHTS;
409
- return [4 /*yield*/, this.request(resource, {
410
- id: id,
411
- count: count,
412
- cursor: cursor,
413
- })];
414
- case 1:
415
- response = _a.sent();
416
- data = Extractors_1.extractors[resource](response);
417
- return [2 /*return*/, data];
418
- }
419
- });
290
+ async highlights(id, count, cursor) {
291
+ const resource = Resource_1.EResourceType.USER_HIGHLIGHTS;
292
+ // Fetching raw list of highlights
293
+ const response = await this.request(resource, {
294
+ id: id,
295
+ count: count,
296
+ cursor: cursor,
420
297
  });
421
- };
298
+ // Deserializing response
299
+ const data = Extractors_1.extractors[resource](response);
300
+ return data;
301
+ }
422
302
  /**
423
303
  * Get the list of tweets liked by the logged in user.
424
304
  *
@@ -444,26 +324,18 @@ var UserService = /** @class */ (function (_super) {
444
324
  * });
445
325
  * ```
446
326
  */
447
- UserService.prototype.likes = function (count, cursor) {
448
- return __awaiter(this, void 0, void 0, function () {
449
- var resource, response, data;
450
- return __generator(this, function (_a) {
451
- switch (_a.label) {
452
- case 0:
453
- resource = Resource_1.EResourceType.USER_LIKES;
454
- return [4 /*yield*/, this.request(resource, {
455
- id: this.userId,
456
- count: count,
457
- cursor: cursor,
458
- })];
459
- case 1:
460
- response = _a.sent();
461
- data = Extractors_1.extractors[resource](response);
462
- return [2 /*return*/, data];
463
- }
464
- });
327
+ async likes(count, cursor) {
328
+ const resource = Resource_1.EResourceType.USER_LIKES;
329
+ // Fetching raw list of likes
330
+ const response = await this.request(resource, {
331
+ id: this.userId,
332
+ count: count,
333
+ cursor: cursor,
465
334
  });
466
- };
335
+ // Deserializing response
336
+ const data = Extractors_1.extractors[resource](response);
337
+ return data;
338
+ }
467
339
  /**
468
340
  * Get the media timeline of a user.
469
341
  *
@@ -490,26 +362,18 @@ var UserService = /** @class */ (function (_super) {
490
362
  * });
491
363
  * ```
492
364
  */
493
- UserService.prototype.media = function (id, count, cursor) {
494
- return __awaiter(this, void 0, void 0, function () {
495
- var resource, response, data;
496
- return __generator(this, function (_a) {
497
- switch (_a.label) {
498
- case 0:
499
- resource = Resource_1.EResourceType.USER_MEDIA;
500
- return [4 /*yield*/, this.request(resource, {
501
- id: id,
502
- count: count,
503
- cursor: cursor,
504
- })];
505
- case 1:
506
- response = _a.sent();
507
- data = Extractors_1.extractors[resource](response);
508
- return [2 /*return*/, data];
509
- }
510
- });
365
+ async media(id, count, cursor) {
366
+ const resource = Resource_1.EResourceType.USER_MEDIA;
367
+ // Fetching raw list of media
368
+ const response = await this.request(resource, {
369
+ id: id,
370
+ count: count,
371
+ cursor: cursor,
511
372
  });
512
- };
373
+ // Deserializing response
374
+ const data = Extractors_1.extractors[resource](response);
375
+ return data;
376
+ }
513
377
  /**
514
378
  * Stream notifications of the logged in user in pseudo real-time.
515
379
  *
@@ -541,59 +405,38 @@ var UserService = /** @class */ (function (_super) {
541
405
  * streamNotifications();
542
406
  * ```
543
407
  */
544
- UserService.prototype.notifications = function (pollingInterval) {
545
- if (pollingInterval === void 0) { pollingInterval = 60000; }
546
- return __asyncGenerator(this, arguments, function notifications_1() {
547
- var resource, first, cursor, response, notifications, _i, _a, notification;
548
- return __generator(this, function (_b) {
549
- switch (_b.label) {
550
- case 0:
551
- resource = Resource_1.EResourceType.USER_NOTIFICATIONS;
552
- first = true;
553
- cursor = undefined;
554
- _b.label = 1;
555
- case 1:
556
- if (!true) return [3 /*break*/, 11];
557
- // Pause execution for the specified polling interval before proceeding to the next iteration
558
- return [4 /*yield*/, __await(new Promise(function (resolve) { return setTimeout(resolve, pollingInterval); }))];
559
- case 2:
560
- // Pause execution for the specified polling interval before proceeding to the next iteration
561
- _b.sent();
562
- return [4 /*yield*/, __await(this.request(resource, {
563
- count: 40,
564
- cursor: cursor,
565
- }))];
566
- case 3:
567
- response = _b.sent();
568
- notifications = Extractors_1.extractors[resource](response);
569
- // Sorting the notifications by time, from oldest to recent
570
- notifications.list.sort(function (a, b) { return new Date(a.receivedAt).valueOf() - new Date(b.receivedAt).valueOf(); });
571
- if (!!first) return [3 /*break*/, 9];
572
- _i = 0, _a = notifications.list;
573
- _b.label = 4;
574
- case 4:
575
- if (!(_i < _a.length)) return [3 /*break*/, 8];
576
- notification = _a[_i];
577
- return [4 /*yield*/, __await(notification)];
578
- case 5: return [4 /*yield*/, _b.sent()];
579
- case 6:
580
- _b.sent();
581
- _b.label = 7;
582
- case 7:
583
- _i++;
584
- return [3 /*break*/, 4];
585
- case 8: return [3 /*break*/, 10];
586
- case 9:
587
- first = false;
588
- _b.label = 10;
589
- case 10:
590
- cursor = notifications.next.value;
591
- return [3 /*break*/, 1];
592
- case 11: return [2 /*return*/];
593
- }
408
+ async *notifications(pollingInterval = 60000) {
409
+ const resource = Resource_1.EResourceType.USER_NOTIFICATIONS;
410
+ /** Whether it's the first batch of notifications or not. */
411
+ let first = true;
412
+ /** The cursor to the last notification received. */
413
+ let cursor = undefined;
414
+ while (true) {
415
+ // Pause execution for the specified polling interval before proceeding to the next iteration
416
+ await new Promise((resolve) => setTimeout(resolve, pollingInterval));
417
+ // Get the batch of notifications after the given cursor
418
+ const response = await this.request(resource, {
419
+ count: 40,
420
+ cursor: cursor,
594
421
  });
595
- });
596
- };
422
+ // Deserializing response
423
+ const notifications = Extractors_1.extractors[resource](response);
424
+ // Sorting the notifications by time, from oldest to recent
425
+ notifications.list.sort((a, b) => new Date(a.receivedAt).valueOf() - new Date(b.receivedAt).valueOf());
426
+ // If not first batch, return new notifications
427
+ if (!first) {
428
+ // Yield the notifications
429
+ for (const notification of notifications.list) {
430
+ yield notification;
431
+ }
432
+ }
433
+ // Else do nothing, do nothing since first batch is notifications that have already been received
434
+ else {
435
+ first = false;
436
+ }
437
+ cursor = notifications.next.value;
438
+ }
439
+ }
597
440
  /**
598
441
  * Get the recommended feed of the logged in user.
599
442
  *
@@ -620,24 +463,16 @@ var UserService = /** @class */ (function (_super) {
620
463
  *
621
464
  * @remarks Always returns 35 feed items, with no way to customize the count.
622
465
  */
623
- UserService.prototype.recommended = function (cursor) {
624
- return __awaiter(this, void 0, void 0, function () {
625
- var resource, response, data;
626
- return __generator(this, function (_a) {
627
- switch (_a.label) {
628
- case 0:
629
- resource = Resource_1.EResourceType.USER_FEED_RECOMMENDED;
630
- return [4 /*yield*/, this.request(resource, {
631
- cursor: cursor,
632
- })];
633
- case 1:
634
- response = _a.sent();
635
- data = Extractors_1.extractors[resource](response);
636
- return [2 /*return*/, data];
637
- }
638
- });
466
+ async recommended(cursor) {
467
+ const resource = Resource_1.EResourceType.USER_FEED_RECOMMENDED;
468
+ // Fetching raw list of tweets
469
+ const response = await this.request(resource, {
470
+ cursor: cursor,
639
471
  });
640
- };
472
+ // Deserializing response
473
+ const data = Extractors_1.extractors[resource](response);
474
+ return data;
475
+ }
641
476
  /**
642
477
  * Get the reply timeline of a user.
643
478
  *
@@ -666,26 +501,18 @@ var UserService = /** @class */ (function (_super) {
666
501
  *
667
502
  * @remarks If the target user has a pinned tweet, the returned reply timeline has one item extra and this is always the pinned tweet.
668
503
  */
669
- UserService.prototype.replies = function (id, count, cursor) {
670
- return __awaiter(this, void 0, void 0, function () {
671
- var resource, response, data;
672
- return __generator(this, function (_a) {
673
- switch (_a.label) {
674
- case 0:
675
- resource = Resource_1.EResourceType.USER_TIMELINE_AND_REPLIES;
676
- return [4 /*yield*/, this.request(resource, {
677
- id: id,
678
- count: count,
679
- cursor: cursor,
680
- })];
681
- case 1:
682
- response = _a.sent();
683
- data = Extractors_1.extractors[resource](response);
684
- return [2 /*return*/, data];
685
- }
686
- });
504
+ async replies(id, count, cursor) {
505
+ const resource = Resource_1.EResourceType.USER_TIMELINE_AND_REPLIES;
506
+ // Fetching raw list of replies
507
+ const response = await this.request(resource, {
508
+ id: id,
509
+ count: count,
510
+ cursor: cursor,
687
511
  });
688
- };
512
+ // Deserializing response
513
+ const data = Extractors_1.extractors[resource](response);
514
+ return data;
515
+ }
689
516
  /**
690
517
  * Get the list of subscriptions of a user.
691
518
  *
@@ -712,26 +539,18 @@ var UserService = /** @class */ (function (_super) {
712
539
  * });
713
540
  * ```
714
541
  */
715
- UserService.prototype.subscriptions = function (id, count, cursor) {
716
- return __awaiter(this, void 0, void 0, function () {
717
- var resource, response, data;
718
- return __generator(this, function (_a) {
719
- switch (_a.label) {
720
- case 0:
721
- resource = Resource_1.EResourceType.USER_SUBSCRIPTIONS;
722
- return [4 /*yield*/, this.request(resource, {
723
- id: id,
724
- count: count,
725
- cursor: cursor,
726
- })];
727
- case 1:
728
- response = _a.sent();
729
- data = Extractors_1.extractors[resource](response);
730
- return [2 /*return*/, data];
731
- }
732
- });
542
+ async subscriptions(id, count, cursor) {
543
+ const resource = Resource_1.EResourceType.USER_SUBSCRIPTIONS;
544
+ // Fetching raw list of subscriptions
545
+ const response = await this.request(resource, {
546
+ id: id,
547
+ count: count,
548
+ cursor: cursor,
733
549
  });
734
- };
550
+ // Deserializing response
551
+ const data = Extractors_1.extractors[resource](response);
552
+ return data;
553
+ }
735
554
  /**
736
555
  * Get the tweet timeline of a user.
737
556
  *
@@ -762,26 +581,18 @@ var UserService = /** @class */ (function (_super) {
762
581
  * - If the target user has a pinned tweet, the returned timeline has one item extra and this is always the pinned tweet.
763
582
  * - If timeline is fetched without authenticating, then the most popular tweets of the target user are returned instead.
764
583
  */
765
- UserService.prototype.timeline = function (id, count, cursor) {
766
- return __awaiter(this, void 0, void 0, function () {
767
- var resource, response, data;
768
- return __generator(this, function (_a) {
769
- switch (_a.label) {
770
- case 0:
771
- resource = Resource_1.EResourceType.USER_TIMELINE;
772
- return [4 /*yield*/, this.request(resource, {
773
- id: id,
774
- count: count,
775
- cursor: cursor,
776
- })];
777
- case 1:
778
- response = _a.sent();
779
- data = Extractors_1.extractors[resource](response);
780
- return [2 /*return*/, data];
781
- }
782
- });
584
+ async timeline(id, count, cursor) {
585
+ const resource = Resource_1.EResourceType.USER_TIMELINE;
586
+ // Fetching raw list of tweets
587
+ const response = await this.request(resource, {
588
+ id: id,
589
+ count: count,
590
+ cursor: cursor,
783
591
  });
784
- };
592
+ // Deserializing response
593
+ const data = Extractors_1.extractors[resource](response);
594
+ return data;
595
+ }
785
596
  /**
786
597
  * Unfollow a user.
787
598
  *
@@ -808,24 +619,14 @@ var UserService = /** @class */ (function (_super) {
808
619
  * });
809
620
  * ```
810
621
  */
811
- UserService.prototype.unfollow = function (id) {
812
- var _a;
813
- return __awaiter(this, void 0, void 0, function () {
814
- var resource, response, data;
815
- return __generator(this, function (_b) {
816
- switch (_b.label) {
817
- case 0:
818
- resource = Resource_1.EResourceType.USER_UNFOLLOW;
819
- return [4 /*yield*/, this.request(Resource_1.EResourceType.USER_UNFOLLOW, { id: id })];
820
- case 1:
821
- response = _b.sent();
822
- data = (_a = Extractors_1.extractors[resource](response)) !== null && _a !== void 0 ? _a : false;
823
- return [2 /*return*/, data];
824
- }
825
- });
826
- });
827
- };
828
- return UserService;
829
- }(FetcherService_1.FetcherService));
622
+ async unfollow(id) {
623
+ const resource = Resource_1.EResourceType.USER_UNFOLLOW;
624
+ // Unfollowing the user
625
+ const response = await this.request(Resource_1.EResourceType.USER_UNFOLLOW, { id: id });
626
+ // Deserializing the response
627
+ const data = Extractors_1.extractors[resource](response) ?? false;
628
+ return data;
629
+ }
630
+ }
830
631
  exports.UserService = UserService;
831
632
  //# sourceMappingURL=UserService.js.map