rettiwt-api 5.0.0-alpha.4 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +160 -87
  2. package/dist/collections/Requests.d.ts +1 -1
  3. package/dist/collections/Requests.js +3 -2
  4. package/dist/collections/Requests.js.map +1 -1
  5. package/dist/collections/Tweet.d.ts +10 -0
  6. package/dist/collections/Tweet.js +17 -0
  7. package/dist/collections/Tweet.js.map +1 -0
  8. package/dist/commands/Tweet.js +0 -16
  9. package/dist/commands/Tweet.js.map +1 -1
  10. package/dist/commands/User.js +0 -15
  11. package/dist/commands/User.js.map +1 -1
  12. package/dist/enums/Tweet.d.ts +8 -0
  13. package/dist/enums/Tweet.js +13 -0
  14. package/dist/enums/Tweet.js.map +1 -0
  15. package/dist/enums/raw/Tweet.d.ts +11 -1
  16. package/dist/enums/raw/Tweet.js +13 -2
  17. package/dist/enums/raw/Tweet.js.map +1 -1
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +1 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/models/RettiwtConfig.d.ts +27 -3
  22. package/dist/models/RettiwtConfig.js +37 -4
  23. package/dist/models/RettiwtConfig.js.map +1 -1
  24. package/dist/models/args/FetchArgs.d.ts +3 -3
  25. package/dist/models/args/FetchArgs.js +3 -2
  26. package/dist/models/args/FetchArgs.js.map +1 -1
  27. package/dist/models/args/PostArgs.d.ts +2 -3
  28. package/dist/models/args/PostArgs.js +3 -3
  29. package/dist/models/args/PostArgs.js.map +1 -1
  30. package/dist/models/auth/AuthCookie.d.ts +1 -1
  31. package/dist/models/auth/AuthCookie.js +1 -1
  32. package/dist/models/auth/AuthCredential.d.ts +1 -1
  33. package/dist/models/auth/AuthCredential.js +1 -1
  34. package/dist/models/data/List.d.ts +1 -1
  35. package/dist/models/data/List.js +1 -1
  36. package/dist/models/data/List.js.map +1 -1
  37. package/dist/models/data/Notification.d.ts +1 -1
  38. package/dist/models/data/Notification.js +1 -1
  39. package/dist/models/data/Notification.js.map +1 -1
  40. package/dist/models/data/Tweet.d.ts +1 -1
  41. package/dist/models/data/Tweet.js +1 -1
  42. package/dist/models/data/Tweet.js.map +1 -1
  43. package/dist/models/data/User.d.ts +1 -1
  44. package/dist/models/data/User.js +1 -1
  45. package/dist/models/data/User.js.map +1 -1
  46. package/dist/requests/Tweet.d.ts +2 -1
  47. package/dist/requests/Tweet.js +3 -4
  48. package/dist/requests/Tweet.js.map +1 -1
  49. package/dist/services/internal/AuthService.d.ts +1 -1
  50. package/dist/services/internal/AuthService.js +1 -1
  51. package/dist/services/internal/TidService.d.ts +0 -1
  52. package/dist/services/internal/TidService.js +10 -15
  53. package/dist/services/internal/TidService.js.map +1 -1
  54. package/dist/services/public/FetcherService.d.ts +4 -3
  55. package/dist/services/public/FetcherService.js +6 -5
  56. package/dist/services/public/FetcherService.js.map +1 -1
  57. package/dist/services/public/ListService.d.ts +6 -4
  58. package/dist/services/public/ListService.js +6 -4
  59. package/dist/services/public/ListService.js.map +1 -1
  60. package/dist/services/public/TweetService.d.ts +96 -74
  61. package/dist/services/public/TweetService.js +97 -87
  62. package/dist/services/public/TweetService.js.map +1 -1
  63. package/dist/services/public/UserService.d.ts +80 -39
  64. package/dist/services/public/UserService.js +84 -43
  65. package/dist/services/public/UserService.js.map +1 -1
  66. package/dist/types/args/FetchArgs.d.ts +8 -0
  67. package/package.json +1 -1
  68. package/src/collections/Requests.ts +5 -2
  69. package/src/collections/Tweet.ts +17 -0
  70. package/src/commands/Tweet.ts +0 -16
  71. package/src/commands/User.ts +0 -15
  72. package/src/enums/Tweet.ts +8 -0
  73. package/src/enums/raw/Tweet.ts +12 -1
  74. package/src/index.ts +1 -0
  75. package/src/models/RettiwtConfig.ts +43 -4
  76. package/src/models/args/FetchArgs.ts +4 -3
  77. package/src/models/args/PostArgs.ts +3 -4
  78. package/src/models/auth/AuthCookie.ts +1 -1
  79. package/src/models/auth/AuthCredential.ts +1 -1
  80. package/src/models/data/List.ts +1 -1
  81. package/src/models/data/Notification.ts +1 -1
  82. package/src/models/data/Tweet.ts +1 -1
  83. package/src/models/data/User.ts +1 -1
  84. package/src/requests/Tweet.ts +4 -5
  85. package/src/services/internal/AuthService.ts +1 -1
  86. package/src/services/internal/TidService.ts +12 -18
  87. package/src/services/public/FetcherService.ts +6 -5
  88. package/src/services/public/ListService.ts +6 -4
  89. package/src/services/public/TweetService.ts +101 -93
  90. package/src/services/public/UserService.ts +88 -47
  91. package/src/types/args/FetchArgs.ts +10 -0
@@ -1,4 +1,4 @@
1
- import { EResourceType } from '../../enums/Resource';
1
+ import { ETweetRepliesSortType } from '../../enums/Tweet';
2
2
  import { IFetchArgs, ITweetFilter } from '../../types/args/FetchArgs';
3
3
 
4
4
  /**
@@ -12,17 +12,18 @@ export class FetchArgs implements IFetchArgs {
12
12
  public filter?: TweetFilter;
13
13
  public id?: string;
14
14
  public ids?: string[];
15
+ public sortBy?: ETweetRepliesSortType;
15
16
 
16
17
  /**
17
- * @param resource - The resource to be fetched.
18
18
  * @param args - Additional user-defined arguments for fetching the resource.
19
19
  */
20
- public constructor(resource: EResourceType, args: IFetchArgs) {
20
+ public constructor(args: IFetchArgs) {
21
21
  this.id = args.id;
22
22
  this.ids = args.ids;
23
23
  this.count = args.count;
24
24
  this.cursor = args.cursor;
25
25
  this.filter = args.filter ? new TweetFilter(args.filter) : undefined;
26
+ this.sortBy = args.sortBy;
26
27
  }
27
28
  }
28
29
 
@@ -1,4 +1,3 @@
1
- import { EResourceType } from '../../enums/Resource';
2
1
  import { INewTweet, INewTweetMedia, IPostArgs, IUploadArgs } from '../../types/args/PostArgs';
3
2
 
4
3
  /**
@@ -15,10 +14,10 @@ export class PostArgs implements IPostArgs {
15
14
  * @param resource - The resource to be posted.
16
15
  * @param args - Additional user-defined arguments for posting the resource.
17
16
  */
18
- public constructor(resource: EResourceType, args: IPostArgs) {
17
+ public constructor(args: IPostArgs) {
19
18
  this.id = args.id;
20
19
  this.tweet = args.tweet ? new NewTweet(args.tweet) : undefined;
21
- this.upload = args.upload ? new UploadArgs(resource, args.upload) : undefined;
20
+ this.upload = args.upload ? new UploadArgs(args.upload) : undefined;
22
21
  }
23
22
  }
24
23
 
@@ -78,7 +77,7 @@ export class UploadArgs implements IUploadArgs {
78
77
  * @param step - The upload step.
79
78
  * @param args - The upload arguments for uploading the media file.
80
79
  */
81
- public constructor(step: EResourceType, args: IUploadArgs) {
80
+ public constructor(args: IUploadArgs) {
82
81
  this.size = args.size;
83
82
  this.media = args.media;
84
83
  this.id = args.id;
@@ -5,7 +5,7 @@ import { IAuthCookie } from '../../types/auth/AuthCookie';
5
5
  /**
6
6
  * The cookie containing the tokens that are used to authenticate against Twitter.
7
7
  *
8
- * @public
8
+ * @internal
9
9
  */
10
10
  export class AuthCookie implements IAuthCookie {
11
11
  /* eslint-disable @typescript-eslint/naming-convention */
@@ -15,7 +15,7 @@ import { AuthCookie } from './AuthCookie';
15
15
  * - authToken, csrfToken, cookie =\> User authentication.
16
16
  * - authToken, guestToken, cookie =\> Guest authentication while logging in.
17
17
  *
18
- * @public
18
+ * @internal
19
19
  */
20
20
  export class AuthCredential implements IAuthCredential {
21
21
  public authToken?: string;
@@ -32,7 +32,7 @@ export class List implements IList {
32
32
  this.createdBy = list.user_results.result.id;
33
33
  }
34
34
 
35
- /** Get the raw list details. */
35
+ /** The raw list details. */
36
36
  public get raw(): IRawList {
37
37
  return { ...this._raw };
38
38
  }
@@ -44,7 +44,7 @@ export class Notification implements INotification {
44
44
  : ENotificationType.UNDEFINED;
45
45
  }
46
46
 
47
- /** Get the raw notification details. */
47
+ /** The raw notification details. */
48
48
  public get raw(): IRawNotification {
49
49
  return { ...this._raw };
50
50
  }
@@ -66,7 +66,7 @@ export class Tweet implements ITweet {
66
66
  this.url = `https://x.com/${this.tweetBy.userName}/status/${this.id}`;
67
67
  }
68
68
 
69
- /** Get the raw tweet details. */
69
+ /** The raw tweet details. */
70
70
  public get raw(): IRawTweet {
71
71
  return { ...this._raw };
72
72
  }
@@ -50,7 +50,7 @@ export class User implements IUser {
50
50
  this.profileImage = user.legacy.profile_image_url_https;
51
51
  }
52
52
 
53
- /** Get the raw user details. */
53
+ /** The raw user details. */
54
54
  public get raw(): IRawUser {
55
55
  return { ...this._raw };
56
56
  }
@@ -1,6 +1,6 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
 
3
- import { ERawTweetSearchResultType } from '../enums/raw/Tweet';
3
+ import { ERawTweetRepliesSortType, ERawTweetSearchResultType } from '../enums/raw/Tweet';
4
4
  import { TweetFilter } from '../models/args/FetchArgs';
5
5
  import { NewTweet } from '../models/args/PostArgs';
6
6
  import { MediaVariable, ReplyVariable } from '../models/params/Variables';
@@ -266,7 +266,7 @@ export class TweetRequests {
266
266
  * @param id - The id of the tweet whose replies are to be fetched.
267
267
  * @param cursor - The cursor to the batch of replies to fetch.
268
268
  */
269
- public static replies(id: string, cursor?: string): AxiosRequestConfig {
269
+ public static replies(id: string, cursor?: string, sortBy?: ERawTweetRepliesSortType): AxiosRequestConfig {
270
270
  return {
271
271
  method: 'get',
272
272
  url: 'https://x.com/i/api/graphql/_8aYOgEDz35BrBcBal1-_w/TweetDetail',
@@ -276,14 +276,13 @@ export class TweetRequests {
276
276
  focalTweetId: id,
277
277
  cursor: cursor,
278
278
  referrer: 'tweet',
279
- controller_data: cursor,
280
279
  with_rux_injections: false,
281
- includePromotedContent: false,
280
+ rankingMode: sortBy ?? ERawTweetRepliesSortType.RELEVACE,
281
+ includePromotedContent: true,
282
282
  withCommunity: true,
283
283
  withQuickPromoteEligibilityTweetFields: true,
284
284
  withBirdwatchNotes: true,
285
285
  withVoice: true,
286
- withV2Timeline: true,
287
286
  }),
288
287
  features: JSON.stringify({
289
288
  rweb_video_screen_enabled: false,
@@ -7,7 +7,7 @@ import { RettiwtConfig } from '../../models/RettiwtConfig';
7
7
  /**
8
8
  * The services that handles authentication.
9
9
  *
10
- * @public
10
+ * @internal
11
11
  */
12
12
  export class AuthService {
13
13
  /** The config object. */
@@ -19,7 +19,6 @@ import { LogService } from './LogService';
19
19
  export class TidService implements ITidProvider {
20
20
  private readonly _cdnUrl: string;
21
21
  private readonly _config: RettiwtConfig;
22
- private readonly _requestHeaders: NonNullable<unknown>;
23
22
  private _dynamicArgs?: ITidDynamicArgs;
24
23
 
25
24
  /**
@@ -28,20 +27,6 @@ export class TidService implements ITidProvider {
28
27
  public constructor(config: RettiwtConfig) {
29
28
  this._cdnUrl = 'https://abs.twimg.com/responsive-web/client-web';
30
29
  this._config = config;
31
- this._requestHeaders = {
32
- /* eslint-disable @typescript-eslint/naming-convention */
33
-
34
- Authority: 'x.com',
35
- 'Accept-Language': 'en-US,en;q=0.9',
36
- 'Cache-Control': 'no-cache',
37
- Referer: 'https://x.com',
38
- 'User-Agent':
39
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
40
- 'X-Twitter-Active-User': 'yes',
41
- 'X-Twitter-Client-Language': 'en',
42
-
43
- /* eslint-enable @typescript-eslint/naming-convention */
44
- };
45
30
  }
46
31
 
47
32
  /**
@@ -69,7 +54,7 @@ export class TidService implements ITidProvider {
69
54
  */
70
55
  private async getHomepageHtml(): Promise<string> {
71
56
  const response = await axios.get<string>('https://x.com', {
72
- headers: this._requestHeaders,
57
+ headers: this._config.headers,
73
58
  httpAgent: this._config.httpsAgent,
74
59
  httpsAgent: this._config.httpsAgent,
75
60
  });
@@ -117,8 +102,12 @@ export class TidService implements ITidProvider {
117
102
  */
118
103
  public async generate(method: string, path: string): Promise<string | undefined> {
119
104
  try {
105
+ // Refreshing dynamic args
106
+ await this.refreshDynamicArgs();
107
+
108
+ // If dynamic args weren't obtained, skip with error
120
109
  if (!this._dynamicArgs) {
121
- this._dynamicArgs = await this.getDynamicArgs();
110
+ throw new Error('Dynamic args failed to generate');
122
111
  }
123
112
 
124
113
  const { verificationKey, frames, indices } = this._dynamicArgs;
@@ -132,7 +121,12 @@ export class TidService implements ITidProvider {
132
121
  indices: indices,
133
122
  extraByte: 3,
134
123
  });
135
- } catch {
124
+ } catch (err) {
125
+ LogService.log(ELogActions.WARNING, {
126
+ message: 'Failed to generated transaction token. Request may or may not work',
127
+ error: err,
128
+ });
129
+
136
130
  return;
137
131
  }
138
132
  }
@@ -137,12 +137,12 @@ export class FetcherService {
137
137
  // Logging
138
138
  LogService.log(ELogActions.VALIDATE, { target: 'FETCH_ARGS' });
139
139
 
140
- return new FetchArgs(resource, args);
140
+ return new FetchArgs(args);
141
141
  } else if (postResources.includes(resource)) {
142
142
  // Logging
143
143
  LogService.log(ELogActions.VALIDATE, { target: 'POST_ARGS' });
144
144
 
145
- return new PostArgs(resource, args);
145
+ return new PostArgs(args);
146
146
  }
147
147
  }
148
148
 
@@ -180,8 +180,9 @@ export class FetcherService {
180
180
  * @returns The raw data response received.
181
181
  *
182
182
  * @example
183
- * Fetching the raw details of a user with username 'user1'
184
- * ```
183
+ *
184
+ * #### Fetching the raw details of a single user, using their username
185
+ * ```ts
185
186
  * import { FetcherService, EResourceType } from 'rettiwt-api';
186
187
  *
187
188
  * // Creating a new FetcherService instance using the given 'API_KEY'
@@ -194,7 +195,7 @@ export class FetcherService {
194
195
  * })
195
196
  * .catch(err => {
196
197
  * console.log(err);
197
- * })
198
+ * });
198
199
  * ```
199
200
  */
200
201
  public async request<T = unknown>(resource: EResourceType, args: IFetchArgs | IPostArgs): Promise<T> {
@@ -22,14 +22,15 @@ export class ListService extends FetcherService {
22
22
  /**
23
23
  * Get the list of members of a tweet list.
24
24
  *
25
- * @param id - The id of target list.
25
+ * @param id - The ID of target list.
26
26
  * @param count - The number of members to fetch, must be \<= 100.
27
27
  * @param cursor - The cursor to the batch of members to fetch.
28
28
  *
29
29
  * @returns The list tweets in the given list.
30
30
  *
31
31
  * @example
32
- * ```
32
+ *
33
+ * ```ts
33
34
  * import { Rettiwt } from 'rettiwt-api';
34
35
  *
35
36
  * // Creating a new Rettiwt instance using the given 'API_KEY'
@@ -66,14 +67,15 @@ export class ListService extends FetcherService {
66
67
  /**
67
68
  * Get the list of tweets from a tweet list.
68
69
  *
69
- * @param id - The id of target list.
70
+ * @param id - The ID of target list.
70
71
  * @param count - The number of tweets to fetch, must be \<= 100.
71
72
  * @param cursor - The cursor to the batch of tweets to fetch.
72
73
  *
73
74
  * @returns The list tweets in the given list.
74
75
  *
75
76
  * @example
76
- * ```
77
+ *
78
+ * ```ts
77
79
  * import { Rettiwt } from 'rettiwt-api';
78
80
  *
79
81
  * // Creating a new Rettiwt instance using the given 'API_KEY'