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.
- package/README.md +160 -87
- package/dist/collections/Requests.d.ts +1 -1
- package/dist/collections/Requests.js +3 -2
- package/dist/collections/Requests.js.map +1 -1
- package/dist/collections/Tweet.d.ts +10 -0
- package/dist/collections/Tweet.js +17 -0
- package/dist/collections/Tweet.js.map +1 -0
- package/dist/commands/Tweet.js +0 -16
- package/dist/commands/Tweet.js.map +1 -1
- package/dist/commands/User.js +0 -15
- package/dist/commands/User.js.map +1 -1
- package/dist/enums/Tweet.d.ts +8 -0
- package/dist/enums/Tweet.js +13 -0
- package/dist/enums/Tweet.js.map +1 -0
- package/dist/enums/raw/Tweet.d.ts +11 -1
- package/dist/enums/raw/Tweet.js +13 -2
- package/dist/enums/raw/Tweet.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/models/RettiwtConfig.d.ts +27 -3
- package/dist/models/RettiwtConfig.js +37 -4
- package/dist/models/RettiwtConfig.js.map +1 -1
- package/dist/models/args/FetchArgs.d.ts +3 -3
- package/dist/models/args/FetchArgs.js +3 -2
- package/dist/models/args/FetchArgs.js.map +1 -1
- package/dist/models/args/PostArgs.d.ts +2 -3
- package/dist/models/args/PostArgs.js +3 -3
- package/dist/models/args/PostArgs.js.map +1 -1
- package/dist/models/auth/AuthCookie.d.ts +1 -1
- package/dist/models/auth/AuthCookie.js +1 -1
- package/dist/models/auth/AuthCredential.d.ts +1 -1
- package/dist/models/auth/AuthCredential.js +1 -1
- package/dist/models/data/List.d.ts +1 -1
- package/dist/models/data/List.js +1 -1
- package/dist/models/data/List.js.map +1 -1
- package/dist/models/data/Notification.d.ts +1 -1
- package/dist/models/data/Notification.js +1 -1
- package/dist/models/data/Notification.js.map +1 -1
- package/dist/models/data/Tweet.d.ts +1 -1
- package/dist/models/data/Tweet.js +1 -1
- package/dist/models/data/Tweet.js.map +1 -1
- package/dist/models/data/User.d.ts +1 -1
- package/dist/models/data/User.js +1 -1
- package/dist/models/data/User.js.map +1 -1
- package/dist/requests/Tweet.d.ts +2 -1
- package/dist/requests/Tweet.js +3 -4
- package/dist/requests/Tweet.js.map +1 -1
- package/dist/services/internal/AuthService.d.ts +1 -1
- package/dist/services/internal/AuthService.js +1 -1
- package/dist/services/internal/TidService.d.ts +0 -1
- package/dist/services/internal/TidService.js +10 -15
- package/dist/services/internal/TidService.js.map +1 -1
- package/dist/services/public/FetcherService.d.ts +4 -3
- package/dist/services/public/FetcherService.js +6 -5
- package/dist/services/public/FetcherService.js.map +1 -1
- package/dist/services/public/ListService.d.ts +6 -4
- package/dist/services/public/ListService.js +6 -4
- package/dist/services/public/ListService.js.map +1 -1
- package/dist/services/public/TweetService.d.ts +96 -74
- package/dist/services/public/TweetService.js +97 -87
- package/dist/services/public/TweetService.js.map +1 -1
- package/dist/services/public/UserService.d.ts +80 -39
- package/dist/services/public/UserService.js +84 -43
- package/dist/services/public/UserService.js.map +1 -1
- package/dist/types/args/FetchArgs.d.ts +8 -0
- package/package.json +1 -1
- package/src/collections/Requests.ts +5 -2
- package/src/collections/Tweet.ts +17 -0
- package/src/commands/Tweet.ts +0 -16
- package/src/commands/User.ts +0 -15
- package/src/enums/Tweet.ts +8 -0
- package/src/enums/raw/Tweet.ts +12 -1
- package/src/index.ts +1 -0
- package/src/models/RettiwtConfig.ts +43 -4
- package/src/models/args/FetchArgs.ts +4 -3
- package/src/models/args/PostArgs.ts +3 -4
- package/src/models/auth/AuthCookie.ts +1 -1
- package/src/models/auth/AuthCredential.ts +1 -1
- package/src/models/data/List.ts +1 -1
- package/src/models/data/Notification.ts +1 -1
- package/src/models/data/Tweet.ts +1 -1
- package/src/models/data/User.ts +1 -1
- package/src/requests/Tweet.ts +4 -5
- package/src/services/internal/AuthService.ts +1 -1
- package/src/services/internal/TidService.ts +12 -18
- package/src/services/public/FetcherService.ts +6 -5
- package/src/services/public/ListService.ts +6 -4
- package/src/services/public/TweetService.ts +101 -93
- package/src/services/public/UserService.ts +88 -47
- package/src/types/args/FetchArgs.ts +10 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
18
|
+
* @internal
|
|
19
19
|
*/
|
|
20
20
|
export class AuthCredential implements IAuthCredential {
|
|
21
21
|
public authToken?: string;
|
package/src/models/data/List.ts
CHANGED
package/src/models/data/Tweet.ts
CHANGED
package/src/models/data/User.ts
CHANGED
package/src/requests/Tweet.ts
CHANGED
|
@@ -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
|
-
|
|
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,
|
|
@@ -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.
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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'
|