rettiwt-api 5.0.0-alpha.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 +6 -23
  68. package/dist/models/data/Tweet.js +93 -97
  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 +28 -70
  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,98 +1,23 @@
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 __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
- 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;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- };
64
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
65
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
66
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
67
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
68
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
69
- 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); }); }; }
70
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
71
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
72
- function fulfill(value) { resume("next", value); }
73
- function reject(value) { resume("throw", value); }
74
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
75
- };
76
2
  Object.defineProperty(exports, "__esModule", { value: true });
77
3
  exports.TweetService = void 0;
78
- var fs_1 = require("fs");
79
- var Extractors_1 = require("../../collections/Extractors");
80
- var Resource_1 = require("../../enums/Resource");
81
- var FetcherService_1 = require("./FetcherService");
4
+ const fs_1 = require("fs");
5
+ const Extractors_1 = require("../../collections/Extractors");
6
+ const Resource_1 = require("../../enums/Resource");
7
+ const FetcherService_1 = require("./FetcherService");
82
8
  /**
83
9
  * Handles interacting with resources related to tweets.
84
10
  *
85
11
  * @public
86
12
  */
87
- var TweetService = /** @class */ (function (_super) {
88
- __extends(TweetService, _super);
13
+ class TweetService extends FetcherService_1.FetcherService {
89
14
  /**
90
15
  * @param config - The config object for configuring the Rettiwt instance.
91
16
  *
92
17
  * @internal
93
18
  */
94
- function TweetService(config) {
95
- return _super.call(this, config) || this;
19
+ constructor(config) {
20
+ super(config);
96
21
  }
97
22
  /**
98
23
  * Get the details of a tweet.
@@ -120,30 +45,27 @@ var TweetService = /** @class */ (function (_super) {
120
45
  * });
121
46
  * ```
122
47
  */
123
- TweetService.prototype.details = function (id) {
124
- return __awaiter(this, void 0, void 0, function () {
125
- var resource, response, data, response, data;
126
- return __generator(this, function (_a) {
127
- switch (_a.label) {
128
- case 0:
129
- if (!(this.userId != undefined)) return [3 /*break*/, 2];
130
- resource = Resource_1.EResourceType.TWEET_DETAILS_ALT;
131
- return [4 /*yield*/, this.request(resource, { id: id })];
132
- case 1:
133
- response = _a.sent();
134
- data = Extractors_1.extractors[resource](response, id);
135
- return [2 /*return*/, data];
136
- case 2:
137
- resource = Resource_1.EResourceType.TWEET_DETAILS;
138
- return [4 /*yield*/, this.request(resource, { id: id })];
139
- case 3:
140
- response = _a.sent();
141
- data = Extractors_1.extractors[resource](response, id);
142
- return [2 /*return*/, data];
143
- }
144
- });
145
- });
146
- };
48
+ async details(id) {
49
+ let resource;
50
+ // If user is authenticated
51
+ if (this.userId != undefined) {
52
+ resource = Resource_1.EResourceType.TWEET_DETAILS_ALT;
53
+ // Fetching raw tweet details
54
+ const response = await this.request(resource, { id: id });
55
+ // Deserializing response
56
+ const data = Extractors_1.extractors[resource](response, id);
57
+ return data;
58
+ }
59
+ // If user is not authenticated
60
+ else {
61
+ resource = Resource_1.EResourceType.TWEET_DETAILS;
62
+ // Fetching raw tweet details
63
+ const response = await this.request(resource, { id: id });
64
+ // Deserializing response
65
+ const data = Extractors_1.extractors[resource](response, id);
66
+ return data;
67
+ }
68
+ }
147
69
  /**
148
70
  * Like a tweet.
149
71
  *
@@ -168,25 +90,16 @@ var TweetService = /** @class */ (function (_super) {
168
90
  * });
169
91
  * ```
170
92
  */
171
- TweetService.prototype.like = function (id) {
172
- var _a;
173
- return __awaiter(this, void 0, void 0, function () {
174
- var resource, response, data;
175
- return __generator(this, function (_b) {
176
- switch (_b.label) {
177
- case 0:
178
- resource = Resource_1.EResourceType.TWEET_LIKE;
179
- return [4 /*yield*/, this.request(resource, {
180
- id: id,
181
- })];
182
- case 1:
183
- response = _b.sent();
184
- data = (_a = Extractors_1.extractors[resource](response)) !== null && _a !== void 0 ? _a : false;
185
- return [2 /*return*/, data];
186
- }
187
- });
93
+ async like(id) {
94
+ const resource = Resource_1.EResourceType.TWEET_LIKE;
95
+ // Favoriting the tweet
96
+ const response = await this.request(resource, {
97
+ id: id,
188
98
  });
189
- };
99
+ // Deserializing response
100
+ const data = Extractors_1.extractors[resource](response) ?? false;
101
+ return data;
102
+ }
190
103
  /**
191
104
  * Get the list of tweets from a tweet list.
192
105
  *
@@ -215,28 +128,20 @@ var TweetService = /** @class */ (function (_super) {
215
128
  *
216
129
  * @remarks Due a bug in Twitter API, the count is ignored when no cursor is provided and defaults to 100.
217
130
  */
218
- TweetService.prototype.list = function (id, count, cursor) {
219
- return __awaiter(this, void 0, void 0, function () {
220
- var resource, response, data;
221
- return __generator(this, function (_a) {
222
- switch (_a.label) {
223
- case 0:
224
- resource = Resource_1.EResourceType.LIST_TWEETS;
225
- return [4 /*yield*/, this.request(resource, {
226
- id: id,
227
- count: count,
228
- cursor: cursor,
229
- })];
230
- case 1:
231
- response = _a.sent();
232
- data = Extractors_1.extractors[resource](response);
233
- // Sorting the tweets by date, from recent to oldest
234
- data.list.sort(function (a, b) { return new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf(); });
235
- return [2 /*return*/, data];
236
- }
237
- });
131
+ async list(id, count, cursor) {
132
+ const resource = Resource_1.EResourceType.LIST_TWEETS;
133
+ // Fetching raw list tweets
134
+ const response = await this.request(resource, {
135
+ id: id,
136
+ count: count,
137
+ cursor: cursor,
238
138
  });
239
- };
139
+ // Deserializing response
140
+ const data = Extractors_1.extractors[resource](response);
141
+ // Sorting the tweets by date, from recent to oldest
142
+ data.list.sort((a, b) => new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf());
143
+ return data;
144
+ }
240
145
  /**
241
146
  * Post a tweet.
242
147
  *
@@ -316,22 +221,50 @@ var TweetService = /** @class */ (function (_super) {
316
221
  * });
317
222
  * ```
318
223
  */
319
- TweetService.prototype.post = function (options) {
320
- return __awaiter(this, void 0, void 0, function () {
321
- var resource, response, data;
322
- return __generator(this, function (_a) {
323
- switch (_a.label) {
324
- case 0:
325
- resource = Resource_1.EResourceType.TWEET_POST;
326
- return [4 /*yield*/, this.request(resource, { tweet: options })];
327
- case 1:
328
- response = _a.sent();
329
- data = Extractors_1.extractors[resource](response);
330
- return [2 /*return*/, data];
331
- }
332
- });
224
+ async post(options) {
225
+ const resource = Resource_1.EResourceType.TWEET_POST;
226
+ // Posting the tweet
227
+ const response = await this.request(resource, { tweet: options });
228
+ // Deserializing response
229
+ const data = Extractors_1.extractors[resource](response);
230
+ return data;
231
+ }
232
+ /**
233
+ * Get the list of replies to a tweet.
234
+ *
235
+ * @param id - The id of the target tweet.
236
+ * @param cursor - The cursor to the batch of replies to fetch.
237
+ *
238
+ * @returns The list of replies to the given tweet.
239
+ *
240
+ * @example
241
+ * ```
242
+ * import { Rettiwt } from 'rettiwt-api';
243
+ *
244
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
245
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
246
+ *
247
+ * // Fetching the first 100 replies to the Tweet with id '1234567890'
248
+ * rettiwt.tweet.replies('1234567890')
249
+ * .then(res => {
250
+ * console.log(res);
251
+ * })
252
+ * .catch(err => {
253
+ * console.log(err);
254
+ * });
255
+ * ```
256
+ */
257
+ async replies(id, cursor) {
258
+ const resource = Resource_1.EResourceType.TWEET_REPLIES;
259
+ // Fetching raw list of replies
260
+ const response = await this.request(resource, {
261
+ id: id,
262
+ cursor: cursor,
333
263
  });
334
- };
264
+ // Deserializing response
265
+ const data = Extractors_1.extractors[resource](response);
266
+ return data;
267
+ }
335
268
  /**
336
269
  * Retweet a tweet.
337
270
  *
@@ -356,23 +289,14 @@ var TweetService = /** @class */ (function (_super) {
356
289
  * });
357
290
  * ```
358
291
  */
359
- TweetService.prototype.retweet = function (id) {
360
- var _a;
361
- return __awaiter(this, void 0, void 0, function () {
362
- var resource, response, data;
363
- return __generator(this, function (_b) {
364
- switch (_b.label) {
365
- case 0:
366
- resource = Resource_1.EResourceType.TWEET_RETWEET;
367
- return [4 /*yield*/, this.request(resource, { id: id })];
368
- case 1:
369
- response = _b.sent();
370
- data = (_a = Extractors_1.extractors[resource](response)) !== null && _a !== void 0 ? _a : false;
371
- return [2 /*return*/, data];
372
- }
373
- });
374
- });
375
- };
292
+ async retweet(id) {
293
+ const resource = Resource_1.EResourceType.TWEET_RETWEET;
294
+ // Retweeting the tweet
295
+ const response = await this.request(resource, { id: id });
296
+ // Deserializing response
297
+ const data = Extractors_1.extractors[resource](response) ?? false;
298
+ return data;
299
+ }
376
300
  /**
377
301
  * Get the list of users who retweeted a tweet.
378
302
  *
@@ -399,26 +323,18 @@ var TweetService = /** @class */ (function (_super) {
399
323
  * });
400
324
  * ```
401
325
  */
402
- TweetService.prototype.retweeters = 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.TWEET_RETWEETERS;
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
- });
326
+ async retweeters(id, count, cursor) {
327
+ const resource = Resource_1.EResourceType.TWEET_RETWEETERS;
328
+ // Fetching raw list of retweeters
329
+ const response = await this.request(resource, {
330
+ id: id,
331
+ count: count,
332
+ cursor: cursor,
420
333
  });
421
- };
334
+ // Deserializing response
335
+ const data = Extractors_1.extractors[resource](response);
336
+ return data;
337
+ }
422
338
  /**
423
339
  * Schedule a tweet.
424
340
  *
@@ -447,22 +363,14 @@ var TweetService = /** @class */ (function (_super) {
447
363
  * @remarks
448
364
  * Scheduling a tweet is similar to {@link post}ing, except that an extra parameter called `scheduleFor` is used.
449
365
  */
450
- TweetService.prototype.schedule = function (options) {
451
- return __awaiter(this, void 0, void 0, function () {
452
- var resource, response, data;
453
- return __generator(this, function (_a) {
454
- switch (_a.label) {
455
- case 0:
456
- resource = Resource_1.EResourceType.TWEET_SCHEDULE;
457
- return [4 /*yield*/, this.request(resource, { tweet: options })];
458
- case 1:
459
- response = _a.sent();
460
- data = Extractors_1.extractors[resource](response);
461
- return [2 /*return*/, data];
462
- }
463
- });
464
- });
465
- };
366
+ async schedule(options) {
367
+ const resource = Resource_1.EResourceType.TWEET_SCHEDULE;
368
+ // Scheduling the tweet
369
+ const response = await this.request(resource, { tweet: options });
370
+ // Deserializing response
371
+ const data = Extractors_1.extractors[resource](response);
372
+ return data;
373
+ }
466
374
  /**
467
375
  * Search for tweets using a filter.
468
376
  *
@@ -492,29 +400,21 @@ var TweetService = /** @class */ (function (_super) {
492
400
  *
493
401
  * @remarks For details about available filters, refer to {@link TweetFilter}
494
402
  */
495
- TweetService.prototype.search = function (filter, count, cursor, results) {
496
- return __awaiter(this, void 0, void 0, function () {
497
- var resource, response, data;
498
- return __generator(this, function (_a) {
499
- switch (_a.label) {
500
- case 0:
501
- resource = Resource_1.EResourceType.TWEET_SEARCH;
502
- return [4 /*yield*/, this.request(resource, {
503
- filter: filter,
504
- count: count,
505
- cursor: cursor,
506
- results: results,
507
- })];
508
- case 1:
509
- response = _a.sent();
510
- data = Extractors_1.extractors[resource](response);
511
- // Sorting the tweets by date, from recent to oldest
512
- data.list.sort(function (a, b) { return new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf(); });
513
- return [2 /*return*/, data];
514
- }
515
- });
403
+ async search(filter, count, cursor, results) {
404
+ const resource = Resource_1.EResourceType.TWEET_SEARCH;
405
+ // Fetching raw list of filtered tweets
406
+ const response = await this.request(resource, {
407
+ filter: filter,
408
+ count: count,
409
+ cursor: cursor,
410
+ results: results,
516
411
  });
517
- };
412
+ // Deserializing response
413
+ const data = Extractors_1.extractors[resource](response);
414
+ // Sorting the tweets by date, from recent to oldest
415
+ data.list.sort((a, b) => new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf());
416
+ return data;
417
+ }
518
418
  /**
519
419
  * Stream tweets in pseudo real-time using a filter.
520
420
  *
@@ -547,61 +447,35 @@ var TweetService = /** @class */ (function (_super) {
547
447
  * streamTweets();
548
448
  * ```
549
449
  */
550
- TweetService.prototype.stream = function (filter, pollingInterval) {
551
- if (pollingInterval === void 0) { pollingInterval = 60000; }
552
- return __asyncGenerator(this, arguments, function stream_1() {
553
- var startDate, cursor, sinceId, nextSinceId, tweets, _i, _a, tweet;
554
- return __generator(this, function (_b) {
555
- switch (_b.label) {
556
- case 0:
557
- startDate = new Date();
558
- cursor = undefined;
559
- sinceId = undefined;
560
- nextSinceId = undefined;
561
- _b.label = 1;
562
- case 1:
563
- if (!true) return [3 /*break*/, 9];
564
- // Pause execution for the specified polling interval before proceeding to the next iteration
565
- return [4 /*yield*/, __await(new Promise(function (resolve) { return setTimeout(resolve, pollingInterval); }))];
566
- case 2:
567
- // Pause execution for the specified polling interval before proceeding to the next iteration
568
- _b.sent();
569
- return [4 /*yield*/, __await(this.search(__assign(__assign({}, filter), { startDate: startDate, sinceId: sinceId }), undefined, cursor))];
570
- case 3:
571
- tweets = _b.sent();
572
- _i = 0, _a = tweets.list;
573
- _b.label = 4;
574
- case 4:
575
- if (!(_i < _a.length)) return [3 /*break*/, 8];
576
- tweet = _a[_i];
577
- return [4 /*yield*/, __await(tweet)];
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:
586
- // Store the most recent tweet ID from this batch
587
- if (tweets.list.length > 0 && cursor === undefined) {
588
- nextSinceId = tweets.list[0].id;
589
- }
590
- // If there are more tweets to fetch, adjust the cursor value
591
- if (tweets.list.length > 0 && tweets.next) {
592
- cursor = tweets.next.value;
593
- }
594
- // Else, start the next iteration from this batch's most recent tweet
595
- else {
596
- sinceId = nextSinceId;
597
- cursor = undefined;
598
- }
599
- return [3 /*break*/, 1];
600
- case 9: return [2 /*return*/];
601
- }
602
- });
603
- });
604
- };
450
+ async *stream(filter, pollingInterval = 60000) {
451
+ const startDate = new Date();
452
+ let cursor = undefined;
453
+ let sinceId = undefined;
454
+ let nextSinceId = undefined;
455
+ while (true) {
456
+ // Pause execution for the specified polling interval before proceeding to the next iteration
457
+ await new Promise((resolve) => setTimeout(resolve, pollingInterval));
458
+ // Search for tweets
459
+ const tweets = await this.search({ ...filter, startDate: startDate, sinceId: sinceId }, undefined, cursor);
460
+ // Yield the matching tweets
461
+ for (const tweet of tweets.list) {
462
+ yield tweet;
463
+ }
464
+ // Store the most recent tweet ID from this batch
465
+ if (tweets.list.length > 0 && cursor === undefined) {
466
+ nextSinceId = tweets.list[0].id;
467
+ }
468
+ // If there are more tweets to fetch, adjust the cursor value
469
+ if (tweets.list.length > 0 && tweets.next) {
470
+ cursor = tweets.next.value;
471
+ }
472
+ // Else, start the next iteration from this batch's most recent tweet
473
+ else {
474
+ sinceId = nextSinceId;
475
+ cursor = undefined;
476
+ }
477
+ }
478
+ }
605
479
  /**
606
480
  * Unlike a tweet.
607
481
  *
@@ -626,23 +500,14 @@ var TweetService = /** @class */ (function (_super) {
626
500
  * });
627
501
  * ```
628
502
  */
629
- TweetService.prototype.unlike = function (id) {
630
- var _a;
631
- return __awaiter(this, void 0, void 0, function () {
632
- var resource, response, data;
633
- return __generator(this, function (_b) {
634
- switch (_b.label) {
635
- case 0:
636
- resource = Resource_1.EResourceType.TWEET_UNLIKE;
637
- return [4 /*yield*/, this.request(resource, { id: id })];
638
- case 1:
639
- response = _b.sent();
640
- data = (_a = Extractors_1.extractors[resource](response)) !== null && _a !== void 0 ? _a : false;
641
- return [2 /*return*/, data];
642
- }
643
- });
644
- });
645
- };
503
+ async unlike(id) {
504
+ const resource = Resource_1.EResourceType.TWEET_UNLIKE;
505
+ // Unliking the tweet
506
+ const response = await this.request(resource, { id: id });
507
+ // Deserializing the response
508
+ const data = Extractors_1.extractors[resource](response) ?? false;
509
+ return data;
510
+ }
646
511
  /**
647
512
  * Unpost a tweet.
648
513
  *
@@ -667,23 +532,14 @@ var TweetService = /** @class */ (function (_super) {
667
532
  * });
668
533
  * ```
669
534
  */
670
- TweetService.prototype.unpost = function (id) {
671
- var _a;
672
- return __awaiter(this, void 0, void 0, function () {
673
- var resource, response, data;
674
- return __generator(this, function (_b) {
675
- switch (_b.label) {
676
- case 0:
677
- resource = Resource_1.EResourceType.TWEET_UNPOST;
678
- return [4 /*yield*/, this.request(resource, { id: id })];
679
- case 1:
680
- response = _b.sent();
681
- data = (_a = Extractors_1.extractors[resource](response)) !== null && _a !== void 0 ? _a : false;
682
- return [2 /*return*/, data];
683
- }
684
- });
685
- });
686
- };
535
+ async unpost(id) {
536
+ const resource = Resource_1.EResourceType.TWEET_UNPOST;
537
+ // Unposting the tweet
538
+ const response = await this.request(resource, { id: id });
539
+ // Deserializing the response
540
+ const data = Extractors_1.extractors[resource](response) ?? false;
541
+ return data;
542
+ }
687
543
  /**
688
544
  * Unretweet a tweet.
689
545
  *
@@ -708,23 +564,14 @@ var TweetService = /** @class */ (function (_super) {
708
564
  * });
709
565
  * ```
710
566
  */
711
- TweetService.prototype.unretweet = function (id) {
712
- var _a;
713
- return __awaiter(this, void 0, void 0, function () {
714
- var resource, response, data;
715
- return __generator(this, function (_b) {
716
- switch (_b.label) {
717
- case 0:
718
- resource = Resource_1.EResourceType.TWEET_UNRETWEET;
719
- return [4 /*yield*/, this.request(resource, { id: id })];
720
- case 1:
721
- response = _b.sent();
722
- data = (_a = Extractors_1.extractors[resource](response)) !== null && _a !== void 0 ? _a : false;
723
- return [2 /*return*/, data];
724
- }
725
- });
726
- });
727
- };
567
+ async unretweet(id) {
568
+ const resource = Resource_1.EResourceType.TWEET_UNRETWEET;
569
+ // Unretweeting the tweet
570
+ const response = await this.request(resource, { id: id });
571
+ // Deserializing the response
572
+ const data = Extractors_1.extractors[resource](response) ?? false;
573
+ return data;
574
+ }
728
575
  /**
729
576
  * Unschedule a tweet.
730
577
  *
@@ -749,23 +596,14 @@ var TweetService = /** @class */ (function (_super) {
749
596
  * });
750
597
  * ```
751
598
  */
752
- TweetService.prototype.unschedule = function (id) {
753
- var _a;
754
- return __awaiter(this, void 0, void 0, function () {
755
- var resource, response, data;
756
- return __generator(this, function (_b) {
757
- switch (_b.label) {
758
- case 0:
759
- resource = Resource_1.EResourceType.TWEET_UNSCHEDULE;
760
- return [4 /*yield*/, this.request(resource, { id: id })];
761
- case 1:
762
- response = _b.sent();
763
- data = (_a = Extractors_1.extractors[resource](response)) !== null && _a !== void 0 ? _a : false;
764
- return [2 /*return*/, data];
765
- }
766
- });
767
- });
768
- };
599
+ async unschedule(id) {
600
+ const resource = Resource_1.EResourceType.TWEET_UNSCHEDULE;
601
+ // Unscheduling the tweet
602
+ const response = await this.request(resource, { id: id });
603
+ // Deserializing the response
604
+ const data = Extractors_1.extractors[resource](response) ?? false;
605
+ return data;
606
+ }
769
607
  /**
770
608
  * Upload a media file to Twitter.
771
609
  *
@@ -795,34 +633,18 @@ var TweetService = /** @class */ (function (_super) {
795
633
  * If not posted in a tweet within this period, the uploaded media is removed.
796
634
  * - Instead of a path to the media, an ArrayBuffer containing the media can also be uploaded.
797
635
  */
798
- TweetService.prototype.upload = function (media) {
799
- return __awaiter(this, void 0, void 0, function () {
800
- var size, id;
801
- return __generator(this, function (_a) {
802
- switch (_a.label) {
803
- case 0:
804
- size = typeof media == 'string' ? (0, fs_1.statSync)(media).size : media.byteLength;
805
- return [4 /*yield*/, this.request(Resource_1.EResourceType.MEDIA_UPLOAD_INITIALIZE, {
806
- upload: { size: size },
807
- })];
808
- case 1:
809
- id = (_a.sent()).media_id_string;
810
- // APPEND
811
- return [4 /*yield*/, this.request(Resource_1.EResourceType.MEDIA_UPLOAD_APPEND, { upload: { id: id, media: media } })];
812
- case 2:
813
- // APPEND
814
- _a.sent();
815
- // FINALIZE
816
- return [4 /*yield*/, this.request(Resource_1.EResourceType.MEDIA_UPLOAD_FINALIZE, { upload: { id: id } })];
817
- case 3:
818
- // FINALIZE
819
- _a.sent();
820
- return [2 /*return*/, id];
821
- }
822
- });
823
- });
824
- };
825
- return TweetService;
826
- }(FetcherService_1.FetcherService));
636
+ async upload(media) {
637
+ // INITIALIZE
638
+ const size = typeof media == 'string' ? (0, fs_1.statSync)(media).size : media.byteLength;
639
+ const id = (await this.request(Resource_1.EResourceType.MEDIA_UPLOAD_INITIALIZE, {
640
+ upload: { size: size },
641
+ })).media_id_string;
642
+ // APPEND
643
+ await this.request(Resource_1.EResourceType.MEDIA_UPLOAD_APPEND, { upload: { id: id, media: media } });
644
+ // FINALIZE
645
+ await this.request(Resource_1.EResourceType.MEDIA_UPLOAD_FINALIZE, { upload: { id: id } });
646
+ return id;
647
+ }
648
+ }
827
649
  exports.TweetService = TweetService;
828
650
  //# sourceMappingURL=TweetService.js.map