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,311 +1,46 @@
1
- import {
2
- ArrayMaxSize,
3
- IsArray,
4
- IsDate,
5
- IsEmpty,
6
- IsNotEmpty,
7
- IsNumberString,
8
- IsObject,
9
- IsOptional,
10
- IsString,
11
- Max,
12
- MaxLength,
13
- MinDate,
14
- validateSync,
15
- } from 'class-validator';
16
-
17
- import { NewTweet, NewTweetMedia } from 'rettiwt-core';
1
+ import { NewTweet } from 'rettiwt-core';
18
2
 
19
3
  import { EResourceType } from '../../enums/Resource';
20
- import { DataValidationError } from '../errors/DataValidationError';
4
+ import { IPostArgs, IUploadArgs } from '../../types/args/PostArgs';
21
5
 
22
6
  /**
23
- * Options specifying the data that is to be posted.
7
+ * Options specifying the media file to be uploaded.
24
8
  *
25
9
  * @public
26
10
  */
27
- export class PostArgs {
28
- /**
29
- * The id of the target resource.
30
- *
31
- * @remarks
32
- * Required only when posting using the following resources:
33
- * - {@link EResourceType.TWEET_LIKE}
34
- * - {@link EResourceType.TWEET_RETWEET}
35
- * - {@link EResourceType.TWEET_UNLIKE}
36
- * - {@link EResourceType.TWEET_UNPOST}
37
- * - {@link EResourceType.TWEET_UNRETWEET}
38
- * - {@link EResourceType.USER_FOLLOW}
39
- * - {@link EResourceType.USER_UNFOLLOW}
40
- */
41
- @IsEmpty({
42
- groups: [
43
- EResourceType.MEDIA_UPLOAD_APPEND,
44
- EResourceType.MEDIA_UPLOAD_FINALIZE,
45
- EResourceType.MEDIA_UPLOAD_INITIALIZE,
46
- EResourceType.TWEET_POST,
47
- EResourceType.TWEET_SCHEDULE,
48
- ],
49
- })
50
- @IsNotEmpty({
51
- groups: [
52
- EResourceType.TWEET_LIKE,
53
- EResourceType.TWEET_RETWEET,
54
- EResourceType.TWEET_UNLIKE,
55
- EResourceType.TWEET_UNPOST,
56
- EResourceType.TWEET_UNRETWEET,
57
- EResourceType.TWEET_UNSCHEDULE,
58
- EResourceType.USER_FOLLOW,
59
- EResourceType.USER_UNFOLLOW,
60
- ],
61
- })
62
- @IsNumberString(undefined, {
63
- groups: [
64
- EResourceType.TWEET_LIKE,
65
- EResourceType.TWEET_RETWEET,
66
- EResourceType.TWEET_UNLIKE,
67
- EResourceType.TWEET_UNPOST,
68
- EResourceType.TWEET_UNRETWEET,
69
- EResourceType.TWEET_UNSCHEDULE,
70
- EResourceType.USER_FOLLOW,
71
- EResourceType.USER_UNFOLLOW,
72
- ],
73
- })
11
+ export class UploadArgs implements IUploadArgs {
74
12
  public id?: string;
13
+ public media?: string | ArrayBuffer;
14
+ public size?: number;
75
15
 
76
16
  /**
77
- * The tweet that is to be posted.
78
- *
79
- * @remarks
80
- * Required only when posting a tweet using {@link EResourceType.TWEET_POST}
81
- */
82
- @IsEmpty({
83
- groups: [
84
- EResourceType.MEDIA_UPLOAD_APPEND,
85
- EResourceType.MEDIA_UPLOAD_FINALIZE,
86
- EResourceType.MEDIA_UPLOAD_INITIALIZE,
87
- EResourceType.TWEET_LIKE,
88
- EResourceType.TWEET_RETWEET,
89
- EResourceType.TWEET_UNLIKE,
90
- EResourceType.TWEET_UNPOST,
91
- EResourceType.TWEET_UNRETWEET,
92
- EResourceType.TWEET_UNSCHEDULE,
93
- EResourceType.USER_FOLLOW,
94
- EResourceType.USER_UNFOLLOW,
95
- ],
96
- })
97
- @IsNotEmpty({ groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
98
- @IsObject({ groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
99
- public tweet?: TweetArgs;
100
-
101
- /**
102
- * The media file to be uploaded.
103
- *
104
- * @remarks
105
- * Required only when uploading a media using the following resources:
106
- * - {@link EResourceType.MEDIA_UPLOAD_APPEND}
107
- * - {@link EResourceType.MEDIA_UPLOAD_FINALIZE}
108
- * - {@link EResourceType.MEDIA_UPLOAD_INITIALIZE}
109
- */
110
- @IsEmpty({
111
- groups: [
112
- EResourceType.TWEET_LIKE,
113
- EResourceType.TWEET_POST,
114
- EResourceType.TWEET_RETWEET,
115
- EResourceType.TWEET_SCHEDULE,
116
- EResourceType.TWEET_UNLIKE,
117
- EResourceType.TWEET_UNPOST,
118
- EResourceType.TWEET_UNRETWEET,
119
- EResourceType.TWEET_UNSCHEDULE,
120
- EResourceType.USER_FOLLOW,
121
- EResourceType.USER_UNFOLLOW,
122
- ],
123
- })
124
- @IsNotEmpty({
125
- groups: [
126
- EResourceType.MEDIA_UPLOAD_INITIALIZE,
127
- EResourceType.MEDIA_UPLOAD_APPEND,
128
- EResourceType.MEDIA_UPLOAD_FINALIZE,
129
- ],
130
- })
131
- @IsObject({
132
- groups: [
133
- EResourceType.MEDIA_UPLOAD_INITIALIZE,
134
- EResourceType.MEDIA_UPLOAD_APPEND,
135
- EResourceType.MEDIA_UPLOAD_FINALIZE,
136
- ],
137
- })
138
- public upload?: UploadArgs;
139
-
140
- /**
141
- * @param resource - The resource to be posted.
142
- * @param args - Additional user-defined arguments for posting the resource.
17
+ * @param step - The upload step.
18
+ * @param args - The upload arguments for uploading the media file.
143
19
  */
144
- public constructor(resource: EResourceType, args: PostArgs) {
20
+ public constructor(step: EResourceType, args: IUploadArgs) {
21
+ this.size = args.size;
22
+ this.media = args.media;
145
23
  this.id = args.id;
146
- this.tweet = args.tweet ? new TweetArgs(resource, args.tweet) : undefined;
147
- this.upload = args.upload ? new UploadArgs(resource, args.upload) : undefined;
148
-
149
- // Validating this object
150
- const validationResult = validateSync(this, { groups: [resource] });
151
-
152
- // If valiation error occured
153
- if (validationResult.length) {
154
- throw new DataValidationError(validationResult);
155
- }
156
- }
157
- }
158
-
159
- /**
160
- * Options specifying the tweet that is to be posted.
161
- *
162
- * @public
163
- */
164
- export class TweetArgs extends NewTweet {
165
- /**
166
- * The list of media to be uploaded.
167
- *
168
- * @remarks
169
- * Maximum number of media items that can be posted is 4.
170
- */
171
- @IsOptional({ groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
172
- @IsArray({ groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
173
- @ArrayMaxSize(4, { groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
174
- @IsObject({ each: true, groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
175
- public media?: TweetMediaArgs[];
176
-
177
- /** The id of the tweet to quote. */
178
- @IsOptional({ groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
179
- @IsNumberString(undefined, { groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
180
- public quote?: string;
181
-
182
- /** The id of the tweet to which the given tweet must be a reply. */
183
- @IsOptional({ groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
184
- @IsNumberString(undefined, { groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
185
- public replyTo?: string;
186
-
187
- /** The date/time at which the tweet must be scheduled to be posted. */
188
- @IsEmpty({ groups: [EResourceType.TWEET_POST] })
189
- @IsNotEmpty({ groups: [EResourceType.TWEET_SCHEDULE] })
190
- @IsDate({ groups: [EResourceType.TWEET_SCHEDULE] })
191
- @MinDate(() => new Date(), { groups: [EResourceType.TWEET_SCHEDULE] })
192
- public scheduleFor?: Date;
193
-
194
- /**
195
- * The text for the tweet to be created.
196
- *
197
- * @remarks
198
- * Length of the tweet must be \<= 280 characters.
199
- */
200
- @IsNotEmpty({ groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
201
- @IsString({ groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
202
- @MaxLength(280, { groups: [EResourceType.TWEET_POST, EResourceType.TWEET_SCHEDULE] })
203
- public text: string;
204
-
205
- /**
206
- * @param args - Arguments specifying the tweet to be posted.
207
- */
208
- public constructor(resource: EResourceType, args: TweetArgs) {
209
- super();
210
- this.media = args.media ? args.media.map((item) => new TweetMediaArgs(item)) : undefined;
211
- this.quote = args.quote;
212
- this.replyTo = args.replyTo;
213
- this.scheduleFor = args.scheduleFor;
214
- this.text = args.text;
215
-
216
- // Validating this object
217
- const validationResult = validateSync(this, { groups: [resource] });
218
-
219
- // If valiation error occured
220
- if (validationResult.length) {
221
- throw new DataValidationError(validationResult);
222
- }
223
24
  }
224
25
  }
225
26
 
226
27
  /**
227
- * Options specifying the media that is to be posted.
28
+ * Options specifying the data that is to be posted.
228
29
  *
229
30
  * @public
230
31
  */
231
- export class TweetMediaArgs extends NewTweetMedia {
232
- /** The id of the media to post. */
233
- @IsNotEmpty()
234
- @IsNumberString()
235
- public id: string;
236
-
237
- /**
238
- * The list of id of the users tagged in the media.
239
- *
240
- * @remarks
241
- * Maximum number of users that can be tagged is 10.
242
- */
243
- @IsOptional()
244
- @IsArray()
245
- @ArrayMaxSize(10)
246
- @IsNumberString(undefined, { each: true })
247
- public tags?: string[];
248
-
249
- /**
250
- * @param args - Arguments specifying the media to be posted.
251
- */
252
- public constructor(args: TweetMediaArgs) {
253
- super();
254
- this.id = args.id;
255
- this.tags = args.tags ?? [];
256
-
257
- // Validating this object
258
- const validationResult = validateSync(this);
259
-
260
- // If validation error occured
261
- if (validationResult.length) {
262
- throw new DataValidationError(validationResult);
263
- }
264
- }
265
- }
266
-
267
- /**
268
- * Options specifying the media file to be uploaded.
269
- *
270
- * @internal
271
- */
272
- export class UploadArgs {
273
- /** The id allocated to the media file to be uploaded. */
274
- @IsEmpty({ groups: [EResourceType.MEDIA_UPLOAD_INITIALIZE] })
275
- @IsNotEmpty({ groups: [EResourceType.MEDIA_UPLOAD_APPEND, EResourceType.MEDIA_UPLOAD_FINALIZE] })
276
- @IsNumberString(undefined, { groups: [EResourceType.MEDIA_UPLOAD_APPEND, EResourceType.MEDIA_UPLOAD_FINALIZE] })
32
+ export class PostArgs implements IPostArgs {
277
33
  public id?: string;
278
-
279
- /** The media file to be uploaded. */
280
- @IsEmpty({ groups: [EResourceType.MEDIA_UPLOAD_FINALIZE, EResourceType.MEDIA_UPLOAD_INITIALIZE] })
281
- @IsNotEmpty({ groups: [EResourceType.MEDIA_UPLOAD_APPEND] })
282
- public media?: string | ArrayBuffer;
283
-
284
- /**
285
- * The size (in bytes) of the media file to be uploaded.
286
- *
287
- * @remarks The size must be \<= 5242880 bytes.
288
- */
289
- @IsEmpty({ groups: [EResourceType.MEDIA_UPLOAD_APPEND, EResourceType.MEDIA_UPLOAD_FINALIZE] })
290
- @IsNotEmpty({ groups: [EResourceType.MEDIA_UPLOAD_INITIALIZE] })
291
- @Max(5242880, { groups: [EResourceType.MEDIA_UPLOAD_INITIALIZE] })
292
- public size?: number;
34
+ public tweet?: NewTweet;
35
+ public upload?: UploadArgs;
293
36
 
294
37
  /**
295
- * @param step - The upload step.
296
- * @param args - The upload arguments for uploading the media file.
38
+ * @param resource - The resource to be posted.
39
+ * @param args - Additional user-defined arguments for posting the resource.
297
40
  */
298
- public constructor(step: EResourceType, args: UploadArgs) {
299
- this.size = args.size;
300
- this.media = args.media;
41
+ public constructor(resource: EResourceType, args: IPostArgs) {
301
42
  this.id = args.id;
302
-
303
- // Validating this object
304
- const validationResult = validateSync(this, { groups: [step] });
305
-
306
- // If validation error occured
307
- if (validationResult.length) {
308
- throw new DataValidationError(validationResult);
309
- }
43
+ this.tweet = args.tweet ? new NewTweet(args.tweet) : undefined;
44
+ this.upload = args.upload ? new UploadArgs(resource, args.upload) : undefined;
310
45
  }
311
46
  }
@@ -0,0 +1,19 @@
1
+ import { IAccountCredential } from '../../types/auth/AccountCredential';
2
+
3
+ /**
4
+ * The credentials of the Twitter account to be logged into.
5
+ */
6
+ export class AccountCredential implements IAccountCredential {
7
+ public email: string;
8
+ public password: string;
9
+ public userName: string;
10
+
11
+ /**
12
+ * @param cred - The credentials to the Twitter account.
13
+ */
14
+ public constructor(cred: IAccountCredential) {
15
+ this.email = cred.email;
16
+ this.userName = cred.userName;
17
+ this.password = cred.password;
18
+ }
19
+ }
@@ -0,0 +1,56 @@
1
+ import { Cookie } from 'cookiejar';
2
+
3
+ import { IAuthCookie } from '../../types/auth/AuthCookie';
4
+
5
+ /**
6
+ * The cookie containing the tokens that are used to authenticate against Twitter.
7
+ */
8
+ export class AuthCookie implements IAuthCookie {
9
+ /* eslint-disable @typescript-eslint/naming-convention */
10
+
11
+ public auth_token: string;
12
+ public ct0: string;
13
+ public kdt: string;
14
+ public twid: string;
15
+
16
+ /* eslint-enable @typescript-eslint/naming-convention */
17
+
18
+ /**
19
+ * @param cookies - The cookie list obtained from the browser.
20
+ */
21
+ public constructor(cookies: Cookie[]) {
22
+ // Initializing defaults
23
+ this.auth_token = '';
24
+ this.ct0 = '';
25
+ this.kdt = '';
26
+ this.twid = '';
27
+
28
+ // Parsing the cookies
29
+ for (const cookie of cookies) {
30
+ if (cookie.name == 'kdt') {
31
+ this.kdt = cookie.value;
32
+ } else if (cookie.name == 'twid') {
33
+ this.twid = cookie.value;
34
+ } else if (cookie.name == 'ct0') {
35
+ this.ct0 = cookie.value;
36
+ } else if (cookie.name == 'auth_token') {
37
+ this.auth_token = cookie.value;
38
+ }
39
+ }
40
+ }
41
+
42
+ /**
43
+ * @returns the string representation of 'this' object.
44
+ */
45
+ public toString(): string {
46
+ /** The string representation of 'this' object. */
47
+ let outStr = '';
48
+
49
+ // Iterating through the (key, value) pairs of this cookie
50
+ for (const [key, value] of Object.entries(this)) {
51
+ outStr += `${key}=${value as string};`;
52
+ }
53
+
54
+ return outStr;
55
+ }
56
+ }
@@ -0,0 +1,83 @@
1
+ import { AxiosHeaders, AxiosRequestHeaders } from 'axios';
2
+
3
+ import { Cookie } from 'cookiejar';
4
+
5
+ import { EAuthenticationType } from '../../enums/Authentication';
6
+ import { IAuthCredential } from '../../types/auth/AuthCredential';
7
+
8
+ import { AuthCookie } from './AuthCookie';
9
+
10
+ /**
11
+ * The credentials for authenticating against Twitter.
12
+ *
13
+ * Depending on which tokens are present, the authentication type is determined as follows:
14
+ * - authToken, guestToken =\> Guest authentication.
15
+ * - authToken, csrfToken, cookie =\> User authentication.
16
+ * - authToken, guestToken, cookie =\> Guest authentication while logging in.
17
+ */
18
+ export class AuthCredential implements IAuthCredential {
19
+ public authToken?: string;
20
+ public authenticationType?: EAuthenticationType;
21
+ public cookies?: string;
22
+ public csrfToken?: string;
23
+ public guestToken?: string;
24
+
25
+ /**
26
+ * @param cookies - The list of cookies to be used for authenticating against Twitter.
27
+ * @param guestToken - The guest token to be used to authenticate a guest session.
28
+ */
29
+ public constructor(cookies?: Cookie[], guestToken?: string) {
30
+ this.authToken =
31
+ 'AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA';
32
+ // If guest credentials given
33
+ if (!cookies && guestToken) {
34
+ this.guestToken = guestToken;
35
+ this.authenticationType = EAuthenticationType.GUEST;
36
+ }
37
+ // If login credentials given
38
+ else if (cookies && guestToken) {
39
+ // Parsing the cookies
40
+ const parsedCookie: AuthCookie = new AuthCookie(cookies);
41
+
42
+ this.cookies = parsedCookie.toString();
43
+ this.guestToken = guestToken;
44
+ this.authenticationType = EAuthenticationType.LOGIN;
45
+ }
46
+ // If user credentials given
47
+ else if (cookies && !guestToken) {
48
+ // Parsing the cookies
49
+ const parsedCookie: AuthCookie = new AuthCookie(cookies);
50
+
51
+ this.cookies = parsedCookie.toString();
52
+ this.csrfToken = parsedCookie.ct0;
53
+ this.authenticationType = EAuthenticationType.USER;
54
+ }
55
+ }
56
+
57
+ /**
58
+ * @returns The HTTP header representation of 'this' object.
59
+ */
60
+ public toHeader(): AxiosRequestHeaders {
61
+ const headers = new AxiosHeaders();
62
+
63
+ /**
64
+ * Conditionally initializing only those data which are supplied.
65
+ *
66
+ * This is done to ensure that the data that is not supplied, is not included in output, not even undefined.
67
+ */
68
+ if (this.authToken) {
69
+ headers.set('authorization', `Bearer ${this.authToken}`);
70
+ }
71
+ if (this.guestToken) {
72
+ headers.set('x-guest-token', this.guestToken);
73
+ }
74
+ if (this.csrfToken) {
75
+ headers.set('x-csrf-token', this.csrfToken);
76
+ }
77
+ if (this.cookies) {
78
+ headers.set('cookie', this.cookies);
79
+ }
80
+
81
+ return headers;
82
+ }
83
+ }
@@ -1,9 +1,11 @@
1
- import { ICursor } from 'rettiwt-core';
1
+ import { ICursor as IRawCursor } from 'rettiwt-core';
2
2
 
3
3
  import { EBaseType } from '../../enums/Data';
4
4
 
5
5
  import { findByFilter } from '../../helper/JsonUtils';
6
6
 
7
+ import { ICursor, ICursoredData } from '../../types/data/CursoredData';
8
+
7
9
  import { Notification } from './Notification';
8
10
  import { Tweet } from './Tweet';
9
11
  import { User } from './User';
@@ -15,11 +17,8 @@ import { User } from './User';
15
17
  *
16
18
  * @public
17
19
  */
18
- export class CursoredData<T extends Notification | Tweet | User> {
19
- /** The batch of data of the given type. */
20
+ export class CursoredData<T extends Notification | Tweet | User> implements ICursoredData<T> {
20
21
  public list: T[] = [];
21
-
22
- /** The cursor to the next batch of data. */
23
22
  public next: Cursor = new Cursor('');
24
23
 
25
24
  /**
@@ -27,15 +26,19 @@ export class CursoredData<T extends Notification | Tweet | User> {
27
26
  * @param type - The base type of the data included in the batch.
28
27
  */
29
28
  public constructor(response: NonNullable<unknown>, type: EBaseType) {
29
+ // Initializing defaults
30
+ this.list = [];
31
+ this.next = new Cursor('');
32
+
30
33
  if (type == EBaseType.TWEET) {
31
34
  this.list = Tweet.list(response) as T[];
32
- this.next = new Cursor(findByFilter<ICursor>(response, 'cursorType', 'Bottom')[0]?.value ?? '');
35
+ this.next = new Cursor(findByFilter<IRawCursor>(response, 'cursorType', 'Bottom')[0]?.value ?? '');
33
36
  } else if (type == EBaseType.USER) {
34
37
  this.list = User.list(response) as T[];
35
- this.next = new Cursor(findByFilter<ICursor>(response, 'cursorType', 'Bottom')[0]?.value ?? '');
38
+ this.next = new Cursor(findByFilter<IRawCursor>(response, 'cursorType', 'Bottom')[0]?.value ?? '');
36
39
  } else if (type == EBaseType.NOTIFICATION) {
37
40
  this.list = Notification.list(response) as T[];
38
- this.next = new Cursor(findByFilter<ICursor>(response, 'cursorType', 'Top')[0]?.value ?? '');
41
+ this.next = new Cursor(findByFilter<IRawCursor>(response, 'cursorType', 'Top')[0]?.value ?? '');
39
42
  }
40
43
  }
41
44
  }
@@ -45,7 +48,7 @@ export class CursoredData<T extends Notification | Tweet | User> {
45
48
  *
46
49
  * @public
47
50
  */
48
- export class Cursor {
51
+ export class Cursor implements ICursor {
49
52
  /** The cursor string. */
50
53
  public value: string;
51
54
 
@@ -1,30 +1,19 @@
1
1
  import { IList as IRawList } from 'rettiwt-core';
2
2
 
3
+ import { IList } from '../../types/data/List';
4
+
3
5
  /**
4
6
  * The details of a single Twitter List.
5
7
  *
6
8
  * @public
7
9
  */
8
- export class List {
9
- /** The date and time of creation of the list, int UTC string format. */
10
+ export class List implements IList {
10
11
  public createdAt: string;
11
-
12
- /** The rest id of the user who created the list. */
13
12
  public createdBy: string;
14
-
15
- /** The list description. */
16
13
  public description?: string;
17
-
18
- /** The rest id of the list. */
19
14
  public id: string;
20
-
21
- /** The number of memeber of the list. */
22
15
  public memberCount: number;
23
-
24
- /** The name of the list. */
25
16
  public name: string;
26
-
27
- /** The number of subscribers of the list. */
28
17
  public subscriberCount: number;
29
18
 
30
19
  /**
@@ -1,52 +1,30 @@
1
1
  import {
2
2
  ENotificationType as ENotificationTypeOriginal,
3
- INotification,
3
+ INotification as IRawNotification,
4
4
  IUserNotificationsResponse,
5
5
  } from 'rettiwt-core';
6
6
 
7
+ import { ENotificationType } from '../../enums/Data';
7
8
  import { findKeyByValue } from '../../helper/JsonUtils';
8
-
9
- /**
10
- * The different types of notifications.
11
- *
12
- * @public
13
- */
14
- export enum ENotificationType {
15
- RECOMMENDATION = 'RECOMMENDATION',
16
- INFORMATION = 'INFORMATION',
17
- LIVE = 'LIVE',
18
- ALERT = 'ALERT',
19
- UNDEFINED = 'UNDEFINED',
20
- }
9
+ import { INotification } from '../../types/data/Notification';
21
10
 
22
11
  /**
23
12
  * The details of a single notification.
24
13
  *
25
14
  * @public
26
15
  */
27
- export class Notification {
28
- /** The list of id of the users from whom the notification was received. */
16
+ export class Notification implements INotification {
29
17
  public from: string[];
30
-
31
- /** The id of the notification. */
32
18
  public id: string;
33
-
34
- /** The text contents of the notification. */
35
19
  public message: string;
36
-
37
- /** The date/time at which the notification was received. */
38
20
  public receivedAt: Date;
39
-
40
- /** The list of id of the target tweet(s) of the notification. */
41
21
  public target: string[];
42
-
43
- /** The type of notification. */
44
22
  public type?: ENotificationType;
45
23
 
46
24
  /**
47
25
  * @param notification - The raw notification details.
48
26
  */
49
- public constructor(notification: INotification) {
27
+ public constructor(notification: IRawNotification) {
50
28
  // Getting the original notification type
51
29
  const notificationType: string | undefined = findKeyByValue(ENotificationTypeOriginal, notification.icon.id);
52
30
 
@@ -82,7 +60,7 @@ export class Notification {
82
60
  for (const [, value] of Object.entries(
83
61
  (response as IUserNotificationsResponse).globalObjects.notifications,
84
62
  )) {
85
- notifications.push(new Notification(value as INotification));
63
+ notifications.push(new Notification(value as IRawNotification));
86
64
  }
87
65
  }
88
66