dp-worker 0.1.24 → 0.1.25
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/dist/bird/sidecar-entry.js +16 -2
- package/dist/bird/sidecar-entry.js.map +1 -1
- package/dist/chrome-extension/omni-flow/manifest.json +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.d.ts +3 -0
- package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.js +14 -0
- package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
- package/package.json +2 -2
- package/vendor/bird/LICENSE +21 -0
- package/vendor/bird/README.md +58 -0
- package/vendor/bird/dist/cli/pagination.d.ts +35 -0
- package/vendor/bird/dist/cli/pagination.js +43 -0
- package/vendor/bird/dist/cli/program.d.ts +5 -0
- package/vendor/bird/dist/cli/program.js +113 -0
- package/vendor/bird/dist/cli/shared.d.ts +77 -0
- package/vendor/bird/dist/cli/shared.js +327 -0
- package/vendor/bird/dist/cli.d.ts +12 -0
- package/vendor/bird/dist/cli.js +29 -0
- package/vendor/bird/dist/commands/bookmarks.d.ts +4 -0
- package/vendor/bird/dist/commands/bookmarks.js +189 -0
- package/vendor/bird/dist/commands/check.d.ts +4 -0
- package/vendor/bird/dist/commands/check.js +43 -0
- package/vendor/bird/dist/commands/follow.d.ts +4 -0
- package/vendor/bird/dist/commands/follow.js +91 -0
- package/vendor/bird/dist/commands/help.d.ts +4 -0
- package/vendor/bird/dist/commands/help.js +19 -0
- package/vendor/bird/dist/commands/home.d.ts +4 -0
- package/vendor/bird/dist/commands/home.js +43 -0
- package/vendor/bird/dist/commands/lists.d.ts +4 -0
- package/vendor/bird/dist/commands/lists.js +125 -0
- package/vendor/bird/dist/commands/news.d.ts +4 -0
- package/vendor/bird/dist/commands/news.js +131 -0
- package/vendor/bird/dist/commands/post.d.ts +4 -0
- package/vendor/bird/dist/commands/post.js +101 -0
- package/vendor/bird/dist/commands/query-ids.d.ts +4 -0
- package/vendor/bird/dist/commands/query-ids.js +80 -0
- package/vendor/bird/dist/commands/read.d.ts +4 -0
- package/vendor/bird/dist/commands/read.js +152 -0
- package/vendor/bird/dist/commands/search.d.ts +4 -0
- package/vendor/bird/dist/commands/search.js +115 -0
- package/vendor/bird/dist/commands/unbookmark.d.ts +4 -0
- package/vendor/bird/dist/commands/unbookmark.js +36 -0
- package/vendor/bird/dist/commands/user-tweets.d.ts +4 -0
- package/vendor/bird/dist/commands/user-tweets.js +109 -0
- package/vendor/bird/dist/commands/users.d.ts +4 -0
- package/vendor/bird/dist/commands/users.js +295 -0
- package/vendor/bird/dist/index.d.ts +2 -0
- package/vendor/bird/dist/index.js +2 -0
- package/vendor/bird/dist/lib/cli-args.d.ts +7 -0
- package/vendor/bird/dist/lib/cli-args.js +25 -0
- package/vendor/bird/dist/lib/cookies.d.ts +31 -0
- package/vendor/bird/dist/lib/cookies.js +81 -0
- package/vendor/bird/dist/lib/extract-bookmark-folder-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-bookmark-folder-id.js +20 -0
- package/vendor/bird/dist/lib/extract-list-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-list-id.js +19 -0
- package/vendor/bird/dist/lib/extract-tweet-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-tweet-id.js +14 -0
- package/vendor/bird/dist/lib/features.json +17 -0
- package/vendor/bird/dist/lib/index.d.ts +10 -0
- package/vendor/bird/dist/lib/index.js +4 -0
- package/vendor/bird/dist/lib/normalize-handle.d.ts +6 -0
- package/vendor/bird/dist/lib/normalize-handle.js +31 -0
- package/vendor/bird/dist/lib/output.d.ts +29 -0
- package/vendor/bird/dist/lib/output.js +88 -0
- package/vendor/bird/dist/lib/paginate-cursor.d.ts +27 -0
- package/vendor/bird/dist/lib/paginate-cursor.js +37 -0
- package/vendor/bird/dist/lib/query-ids.json +20 -0
- package/vendor/bird/dist/lib/runtime-features.d.ts +19 -0
- package/vendor/bird/dist/lib/runtime-features.js +151 -0
- package/vendor/bird/dist/lib/runtime-query-ids.d.ts +33 -0
- package/vendor/bird/dist/lib/runtime-query-ids.js +264 -0
- package/vendor/bird/dist/lib/thread-filters.d.ts +8 -0
- package/vendor/bird/dist/lib/thread-filters.js +124 -0
- package/vendor/bird/dist/lib/twitter-client-base.d.ts +38 -0
- package/vendor/bird/dist/lib/twitter-client-base.js +129 -0
- package/vendor/bird/dist/lib/twitter-client-bookmarks.d.ts +7 -0
- package/vendor/bird/dist/lib/twitter-client-bookmarks.js +61 -0
- package/vendor/bird/dist/lib/twitter-client-constants.d.ts +43 -0
- package/vendor/bird/dist/lib/twitter-client-constants.js +50 -0
- package/vendor/bird/dist/lib/twitter-client-engagement.d.ts +16 -0
- package/vendor/bird/dist/lib/twitter-client-engagement.js +81 -0
- package/vendor/bird/dist/lib/twitter-client-features.d.ts +14 -0
- package/vendor/bird/dist/lib/twitter-client-features.js +347 -0
- package/vendor/bird/dist/lib/twitter-client-follow.d.ts +8 -0
- package/vendor/bird/dist/lib/twitter-client-follow.js +178 -0
- package/vendor/bird/dist/lib/twitter-client-home.d.ts +13 -0
- package/vendor/bird/dist/lib/twitter-client-home.js +138 -0
- package/vendor/bird/dist/lib/twitter-client-lists.d.ts +11 -0
- package/vendor/bird/dist/lib/twitter-client-lists.js +321 -0
- package/vendor/bird/dist/lib/twitter-client-media.d.ts +11 -0
- package/vendor/bird/dist/lib/twitter-client-media.js +136 -0
- package/vendor/bird/dist/lib/twitter-client-news.d.ts +47 -0
- package/vendor/bird/dist/lib/twitter-client-news.js +283 -0
- package/vendor/bird/dist/lib/twitter-client-posting.d.ts +8 -0
- package/vendor/bird/dist/lib/twitter-client-posting.js +218 -0
- package/vendor/bird/dist/lib/twitter-client-search.d.ts +19 -0
- package/vendor/bird/dist/lib/twitter-client-search.js +157 -0
- package/vendor/bird/dist/lib/twitter-client-timelines.d.ts +23 -0
- package/vendor/bird/dist/lib/twitter-client-timelines.js +471 -0
- package/vendor/bird/dist/lib/twitter-client-tweet-detail.d.ts +25 -0
- package/vendor/bird/dist/lib/twitter-client-tweet-detail.js +295 -0
- package/vendor/bird/dist/lib/twitter-client-types.d.ts +407 -0
- package/vendor/bird/dist/lib/twitter-client-types.js +2 -0
- package/vendor/bird/dist/lib/twitter-client-user-lookup.d.ts +16 -0
- package/vendor/bird/dist/lib/twitter-client-user-lookup.js +224 -0
- package/vendor/bird/dist/lib/twitter-client-user-tweets.d.ts +22 -0
- package/vendor/bird/dist/lib/twitter-client-user-tweets.js +154 -0
- package/vendor/bird/dist/lib/twitter-client-users.d.ts +9 -0
- package/vendor/bird/dist/lib/twitter-client-users.js +358 -0
- package/vendor/bird/dist/lib/twitter-client-utils.d.ts +173 -0
- package/vendor/bird/dist/lib/twitter-client-utils.js +511 -0
- package/vendor/bird/dist/lib/twitter-client.d.ts +23 -0
- package/vendor/bird/dist/lib/twitter-client.js +21 -0
- package/vendor/bird/dist/lib/version.d.ts +6 -0
- package/vendor/bird/dist/lib/version.js +174 -0
- package/vendor/bird/upstream-package.json +61 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { paginateCursor } from './paginate-cursor.js';
|
|
2
|
+
import { TWITTER_API_BASE } from './twitter-client-constants.js';
|
|
3
|
+
import { buildArticleFeatures, buildArticleFieldToggles, buildTweetDetailFeatures } from './twitter-client-features.js';
|
|
4
|
+
import { extractArticleText, extractCursorFromInstructions, findTweetInInstructions, firstText, mapTweetResult, parseTweetsFromInstructions, } from './twitter-client-utils.js';
|
|
5
|
+
export function withTweetDetails(Base) {
|
|
6
|
+
class TwitterClientTweetDetails extends Base {
|
|
7
|
+
// biome-ignore lint/complexity/noUselessConstructor lint/suspicious/noExplicitAny: TS mixin constructor requirement.
|
|
8
|
+
constructor(...args) {
|
|
9
|
+
super(...args);
|
|
10
|
+
}
|
|
11
|
+
async fetchUserArticlePlainText(userId, tweetId) {
|
|
12
|
+
const variables = {
|
|
13
|
+
userId,
|
|
14
|
+
count: 20,
|
|
15
|
+
includePromotedContent: true,
|
|
16
|
+
withVoice: true,
|
|
17
|
+
withQuickPromoteEligibilityTweetFields: true,
|
|
18
|
+
withBirdwatchNotes: true,
|
|
19
|
+
withCommunity: true,
|
|
20
|
+
withSafetyModeUserFields: true,
|
|
21
|
+
withSuperFollowsUserFields: true,
|
|
22
|
+
withDownvotePerspective: false,
|
|
23
|
+
withReactionsMetadata: false,
|
|
24
|
+
withReactionsPerspective: false,
|
|
25
|
+
withSuperFollowsTweetFields: true,
|
|
26
|
+
withSuperFollowsReplyCount: false,
|
|
27
|
+
withClientEventToken: false,
|
|
28
|
+
};
|
|
29
|
+
const params = new URLSearchParams({
|
|
30
|
+
variables: JSON.stringify(variables),
|
|
31
|
+
features: JSON.stringify(buildArticleFeatures()),
|
|
32
|
+
fieldToggles: JSON.stringify(buildArticleFieldToggles()),
|
|
33
|
+
});
|
|
34
|
+
const queryId = await this.getQueryId('UserArticlesTweets');
|
|
35
|
+
const url = `${TWITTER_API_BASE}/${queryId}/UserArticlesTweets?${params.toString()}`;
|
|
36
|
+
try {
|
|
37
|
+
const response = await this.fetchWithTimeout(url, { method: 'GET', headers: this.getHeaders() });
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
const data = (await response.json());
|
|
42
|
+
const instructions = data.data?.user?.result?.timeline?.timeline?.instructions ?? [];
|
|
43
|
+
for (const instruction of instructions) {
|
|
44
|
+
for (const entry of instruction.entries ?? []) {
|
|
45
|
+
const result = entry.content?.itemContent?.tweet_results?.result;
|
|
46
|
+
if (result?.rest_id !== tweetId) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const articleResult = result.article?.article_results?.result;
|
|
50
|
+
const title = firstText(articleResult?.title, result.article?.title);
|
|
51
|
+
const plainText = firstText(articleResult?.plain_text, result.article?.plain_text);
|
|
52
|
+
return { title, plainText };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
async fetchTweetDetail(tweetId, cursor) {
|
|
62
|
+
const variables = {
|
|
63
|
+
focalTweetId: tweetId,
|
|
64
|
+
with_rux_injections: false,
|
|
65
|
+
rankingMode: 'Relevance',
|
|
66
|
+
includePromotedContent: true,
|
|
67
|
+
withCommunity: true,
|
|
68
|
+
withQuickPromoteEligibilityTweetFields: true,
|
|
69
|
+
withBirdwatchNotes: true,
|
|
70
|
+
withVoice: true,
|
|
71
|
+
...(cursor ? { cursor } : {}),
|
|
72
|
+
};
|
|
73
|
+
const features = {
|
|
74
|
+
...buildTweetDetailFeatures(),
|
|
75
|
+
articles_preview_enabled: true,
|
|
76
|
+
articles_rest_api_enabled: true,
|
|
77
|
+
responsive_web_graphql_skip_user_profile_image_extensions_enabled: false,
|
|
78
|
+
creator_subscriptions_tweet_preview_api_enabled: true,
|
|
79
|
+
graphql_is_translatable_rweb_tweet_is_translatable_enabled: true,
|
|
80
|
+
view_counts_everywhere_api_enabled: true,
|
|
81
|
+
longform_notetweets_consumption_enabled: true,
|
|
82
|
+
responsive_web_twitter_article_tweet_consumption_enabled: true,
|
|
83
|
+
freedom_of_speech_not_reach_fetch_enabled: true,
|
|
84
|
+
standardized_nudges_misinfo: true,
|
|
85
|
+
tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled: true,
|
|
86
|
+
rweb_video_timestamps_enabled: true,
|
|
87
|
+
};
|
|
88
|
+
const fieldToggles = {
|
|
89
|
+
...buildArticleFieldToggles(),
|
|
90
|
+
withArticleRichContentState: true,
|
|
91
|
+
};
|
|
92
|
+
const params = new URLSearchParams({
|
|
93
|
+
variables: JSON.stringify(variables),
|
|
94
|
+
features: JSON.stringify(features),
|
|
95
|
+
fieldToggles: JSON.stringify(fieldToggles),
|
|
96
|
+
});
|
|
97
|
+
try {
|
|
98
|
+
const parseResponse = async (response) => {
|
|
99
|
+
if (!response.ok) {
|
|
100
|
+
const text = await response.text();
|
|
101
|
+
return { success: false, error: `HTTP ${response.status}: ${text.slice(0, 200)}` };
|
|
102
|
+
}
|
|
103
|
+
const data = (await response.json());
|
|
104
|
+
if (data.errors && data.errors.length > 0) {
|
|
105
|
+
// Twitter API sometimes returns partial errors (e.g., is_translatable failures)
|
|
106
|
+
// alongside valid tweet/thread data. Only fail if nothing useful is present.
|
|
107
|
+
const hasUsableData = Boolean(data.data?.tweetResult?.result ||
|
|
108
|
+
data.data?.threaded_conversation_with_injections_v2?.instructions?.length);
|
|
109
|
+
if (!hasUsableData) {
|
|
110
|
+
return { success: false, error: data.errors.map((e) => e.message).join(', ') };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return { success: true, data: data.data ?? {} };
|
|
114
|
+
};
|
|
115
|
+
let lastError;
|
|
116
|
+
let had404 = false;
|
|
117
|
+
const tryOnce = async () => {
|
|
118
|
+
const queryIds = await this.getTweetDetailQueryIds();
|
|
119
|
+
for (const queryId of queryIds) {
|
|
120
|
+
const url = `${TWITTER_API_BASE}/${queryId}/TweetDetail?${params.toString()}`;
|
|
121
|
+
const response = await this.fetchWithTimeout(url, {
|
|
122
|
+
method: 'GET',
|
|
123
|
+
headers: this.getHeaders(),
|
|
124
|
+
});
|
|
125
|
+
if (response.status !== 404) {
|
|
126
|
+
return await parseResponse(response);
|
|
127
|
+
}
|
|
128
|
+
had404 = true;
|
|
129
|
+
const postResponse = await this.fetchWithTimeout(`${TWITTER_API_BASE}/${queryId}/TweetDetail`, {
|
|
130
|
+
method: 'POST',
|
|
131
|
+
headers: this.getHeaders(),
|
|
132
|
+
body: JSON.stringify({ variables, features, queryId }),
|
|
133
|
+
});
|
|
134
|
+
if (postResponse.status !== 404) {
|
|
135
|
+
return await parseResponse(postResponse);
|
|
136
|
+
}
|
|
137
|
+
lastError = 'HTTP 404';
|
|
138
|
+
}
|
|
139
|
+
return { success: false, error: lastError ?? 'Unknown error fetching tweet detail' };
|
|
140
|
+
};
|
|
141
|
+
const firstAttempt = await tryOnce();
|
|
142
|
+
if (firstAttempt.success) {
|
|
143
|
+
return firstAttempt;
|
|
144
|
+
}
|
|
145
|
+
if (had404) {
|
|
146
|
+
await this.refreshQueryIds();
|
|
147
|
+
return await tryOnce();
|
|
148
|
+
}
|
|
149
|
+
return firstAttempt;
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get tweet details by ID
|
|
157
|
+
*/
|
|
158
|
+
async getTweet(tweetId, options = {}) {
|
|
159
|
+
const { includeRaw = false } = options;
|
|
160
|
+
const response = await this.fetchTweetDetail(tweetId);
|
|
161
|
+
if (!response.success) {
|
|
162
|
+
return response;
|
|
163
|
+
}
|
|
164
|
+
const tweetResult = response.data.tweetResult?.result ??
|
|
165
|
+
findTweetInInstructions(response.data.threaded_conversation_with_injections_v2?.instructions, tweetId);
|
|
166
|
+
const mapped = mapTweetResult(tweetResult, { quoteDepth: this.quoteDepth, includeRaw });
|
|
167
|
+
if (mapped) {
|
|
168
|
+
if (tweetResult?.article) {
|
|
169
|
+
const title = firstText(tweetResult.article.article_results?.result?.title, tweetResult.article.title);
|
|
170
|
+
const articleText = extractArticleText(tweetResult);
|
|
171
|
+
if (title && (!articleText || articleText.trim() === title.trim())) {
|
|
172
|
+
const userId = tweetResult.core?.user_results?.result?.rest_id;
|
|
173
|
+
if (userId) {
|
|
174
|
+
const fallback = await this.fetchUserArticlePlainText(userId, tweetId);
|
|
175
|
+
if (fallback.plainText) {
|
|
176
|
+
mapped.text = fallback.title ? `${fallback.title}\n\n${fallback.plainText}` : fallback.plainText;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return { success: true, tweet: mapped };
|
|
182
|
+
}
|
|
183
|
+
return { success: false, error: 'Tweet not found in response' };
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get replies to a tweet by ID
|
|
187
|
+
*/
|
|
188
|
+
async getReplies(tweetId, options = {}) {
|
|
189
|
+
const { includeRaw = false } = options;
|
|
190
|
+
const response = await this.fetchTweetDetail(tweetId);
|
|
191
|
+
if (!response.success) {
|
|
192
|
+
return response;
|
|
193
|
+
}
|
|
194
|
+
const instructions = response.data.threaded_conversation_with_injections_v2?.instructions;
|
|
195
|
+
const tweets = parseTweetsFromInstructions(instructions, { quoteDepth: this.quoteDepth, includeRaw });
|
|
196
|
+
const replies = tweets.filter((tweet) => tweet.inReplyToStatusId === tweetId);
|
|
197
|
+
return { success: true, tweets: replies };
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get full conversation thread for a tweet ID
|
|
201
|
+
*/
|
|
202
|
+
async getThread(tweetId, options = {}) {
|
|
203
|
+
const { includeRaw = false } = options;
|
|
204
|
+
const response = await this.fetchTweetDetail(tweetId);
|
|
205
|
+
if (!response.success) {
|
|
206
|
+
return response;
|
|
207
|
+
}
|
|
208
|
+
const instructions = response.data.threaded_conversation_with_injections_v2?.instructions;
|
|
209
|
+
const tweets = parseTweetsFromInstructions(instructions, { quoteDepth: this.quoteDepth, includeRaw });
|
|
210
|
+
const target = tweets.find((t) => t.id === tweetId);
|
|
211
|
+
const rootId = target?.conversationId || tweetId;
|
|
212
|
+
const thread = tweets.filter((tweet) => tweet.conversationId === rootId);
|
|
213
|
+
thread.sort((a, b) => {
|
|
214
|
+
const aTime = a.createdAt ? Date.parse(a.createdAt) : 0;
|
|
215
|
+
const bTime = b.createdAt ? Date.parse(b.createdAt) : 0;
|
|
216
|
+
return aTime - bTime;
|
|
217
|
+
});
|
|
218
|
+
return { success: true, tweets: thread };
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Get replies to a tweet with pagination support
|
|
222
|
+
*/
|
|
223
|
+
async getRepliesPaged(tweetId, options = {}) {
|
|
224
|
+
const { includeRaw = false, maxPages, pageDelayMs = 1000 } = options;
|
|
225
|
+
const result = await paginateCursor({
|
|
226
|
+
cursor: options.cursor,
|
|
227
|
+
maxPages,
|
|
228
|
+
pageDelayMs,
|
|
229
|
+
sleep: async (ms) => this.sleep(ms),
|
|
230
|
+
getKey: (tweet) => tweet.id,
|
|
231
|
+
fetchPage: async (cursor) => {
|
|
232
|
+
const response = await this.fetchTweetDetail(tweetId, cursor);
|
|
233
|
+
if (!response.success) {
|
|
234
|
+
return response;
|
|
235
|
+
}
|
|
236
|
+
const instructions = response.data.threaded_conversation_with_injections_v2?.instructions;
|
|
237
|
+
const tweets = parseTweetsFromInstructions(instructions, { quoteDepth: this.quoteDepth, includeRaw });
|
|
238
|
+
const replies = tweets.filter((tweet) => tweet.inReplyToStatusId === tweetId);
|
|
239
|
+
const pageCursor = extractCursorFromInstructions(instructions);
|
|
240
|
+
return { success: true, items: replies, cursor: pageCursor };
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
if (result.success) {
|
|
244
|
+
return { success: true, tweets: result.items, nextCursor: result.nextCursor };
|
|
245
|
+
}
|
|
246
|
+
if (result.items) {
|
|
247
|
+
return { success: false, tweets: result.items, nextCursor: result.nextCursor, error: result.error };
|
|
248
|
+
}
|
|
249
|
+
return { success: false, error: result.error };
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Get full conversation thread with pagination support
|
|
253
|
+
*/
|
|
254
|
+
async getThreadPaged(tweetId, options = {}) {
|
|
255
|
+
const { includeRaw = false, maxPages, pageDelayMs = 1000 } = options;
|
|
256
|
+
let rootId;
|
|
257
|
+
const result = await paginateCursor({
|
|
258
|
+
cursor: options.cursor,
|
|
259
|
+
maxPages,
|
|
260
|
+
pageDelayMs,
|
|
261
|
+
sleep: async (ms) => this.sleep(ms),
|
|
262
|
+
getKey: (tweet) => tweet.id,
|
|
263
|
+
fetchPage: async (cursor) => {
|
|
264
|
+
const response = await this.fetchTweetDetail(tweetId, cursor);
|
|
265
|
+
if (!response.success) {
|
|
266
|
+
return response;
|
|
267
|
+
}
|
|
268
|
+
const instructions = response.data.threaded_conversation_with_injections_v2?.instructions;
|
|
269
|
+
const tweets = parseTweetsFromInstructions(instructions, { quoteDepth: this.quoteDepth, includeRaw });
|
|
270
|
+
if (!rootId) {
|
|
271
|
+
const target = tweets.find((t) => t.id === tweetId);
|
|
272
|
+
rootId = target?.conversationId || tweetId;
|
|
273
|
+
}
|
|
274
|
+
const threadTweets = tweets.filter((tweet) => tweet.conversationId === rootId);
|
|
275
|
+
const pageCursor = extractCursorFromInstructions(instructions);
|
|
276
|
+
return { success: true, items: threadTweets, cursor: pageCursor };
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
const sortedTweets = (result.items ?? []).slice().sort((a, b) => {
|
|
280
|
+
const aTime = a.createdAt ? Date.parse(a.createdAt) : 0;
|
|
281
|
+
const bTime = b.createdAt ? Date.parse(b.createdAt) : 0;
|
|
282
|
+
return aTime - bTime;
|
|
283
|
+
});
|
|
284
|
+
if (result.success) {
|
|
285
|
+
return { success: true, tweets: sortedTweets, nextCursor: result.nextCursor };
|
|
286
|
+
}
|
|
287
|
+
if (result.items) {
|
|
288
|
+
return { success: false, tweets: sortedTweets, nextCursor: result.nextCursor, error: result.error };
|
|
289
|
+
}
|
|
290
|
+
return { success: false, error: result.error };
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return TwitterClientTweetDetails;
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=twitter-client-tweet-detail.js.map
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import type { TwitterCookies } from './cookies.js';
|
|
2
|
+
export interface GraphqlMediaEntity {
|
|
3
|
+
id_str?: string;
|
|
4
|
+
media_url_https?: string;
|
|
5
|
+
type?: 'photo' | 'video' | 'animated_gif';
|
|
6
|
+
url?: string;
|
|
7
|
+
expanded_url?: string;
|
|
8
|
+
sizes?: {
|
|
9
|
+
thumb?: {
|
|
10
|
+
w: number;
|
|
11
|
+
h: number;
|
|
12
|
+
resize: string;
|
|
13
|
+
};
|
|
14
|
+
small?: {
|
|
15
|
+
w: number;
|
|
16
|
+
h: number;
|
|
17
|
+
resize: string;
|
|
18
|
+
};
|
|
19
|
+
medium?: {
|
|
20
|
+
w: number;
|
|
21
|
+
h: number;
|
|
22
|
+
resize: string;
|
|
23
|
+
};
|
|
24
|
+
large?: {
|
|
25
|
+
w: number;
|
|
26
|
+
h: number;
|
|
27
|
+
resize: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
video_info?: {
|
|
31
|
+
duration_millis?: number;
|
|
32
|
+
variants?: Array<{
|
|
33
|
+
bitrate?: number;
|
|
34
|
+
content_type?: string;
|
|
35
|
+
url?: string;
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export type GraphqlTweetResult = {
|
|
40
|
+
__typename?: string;
|
|
41
|
+
rest_id?: string;
|
|
42
|
+
legacy?: {
|
|
43
|
+
full_text?: string;
|
|
44
|
+
created_at?: string;
|
|
45
|
+
reply_count?: number;
|
|
46
|
+
retweet_count?: number;
|
|
47
|
+
favorite_count?: number;
|
|
48
|
+
conversation_id_str?: string;
|
|
49
|
+
in_reply_to_status_id_str?: string | null;
|
|
50
|
+
entities?: {
|
|
51
|
+
media?: GraphqlMediaEntity[];
|
|
52
|
+
};
|
|
53
|
+
extended_entities?: {
|
|
54
|
+
media?: GraphqlMediaEntity[];
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
core?: {
|
|
58
|
+
user_results?: {
|
|
59
|
+
result?: {
|
|
60
|
+
rest_id?: string;
|
|
61
|
+
id?: string;
|
|
62
|
+
legacy?: {
|
|
63
|
+
screen_name?: string;
|
|
64
|
+
name?: string;
|
|
65
|
+
};
|
|
66
|
+
core?: {
|
|
67
|
+
screen_name?: string;
|
|
68
|
+
name?: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
note_tweet?: {
|
|
74
|
+
note_tweet_results?: {
|
|
75
|
+
result?: {
|
|
76
|
+
text?: string;
|
|
77
|
+
richtext?: {
|
|
78
|
+
text?: string;
|
|
79
|
+
};
|
|
80
|
+
rich_text?: {
|
|
81
|
+
text?: string;
|
|
82
|
+
};
|
|
83
|
+
content?: {
|
|
84
|
+
text?: string;
|
|
85
|
+
richtext?: {
|
|
86
|
+
text?: string;
|
|
87
|
+
};
|
|
88
|
+
rich_text?: {
|
|
89
|
+
text?: string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
article?: {
|
|
96
|
+
title?: string;
|
|
97
|
+
preview_text?: string;
|
|
98
|
+
article_results?: {
|
|
99
|
+
result?: {
|
|
100
|
+
title?: string;
|
|
101
|
+
preview_text?: string;
|
|
102
|
+
plain_text?: string;
|
|
103
|
+
text?: string;
|
|
104
|
+
richtext?: {
|
|
105
|
+
text?: string;
|
|
106
|
+
};
|
|
107
|
+
rich_text?: {
|
|
108
|
+
text?: string;
|
|
109
|
+
};
|
|
110
|
+
body?: {
|
|
111
|
+
text?: string;
|
|
112
|
+
richtext?: {
|
|
113
|
+
text?: string;
|
|
114
|
+
};
|
|
115
|
+
rich_text?: {
|
|
116
|
+
text?: string;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
content?: {
|
|
120
|
+
text?: string;
|
|
121
|
+
richtext?: {
|
|
122
|
+
text?: string;
|
|
123
|
+
};
|
|
124
|
+
rich_text?: {
|
|
125
|
+
text?: string;
|
|
126
|
+
};
|
|
127
|
+
items?: Array<{
|
|
128
|
+
text?: string;
|
|
129
|
+
content?: {
|
|
130
|
+
text?: string;
|
|
131
|
+
richtext?: {
|
|
132
|
+
text?: string;
|
|
133
|
+
};
|
|
134
|
+
rich_text?: {
|
|
135
|
+
text?: string;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
}>;
|
|
139
|
+
};
|
|
140
|
+
sections?: Array<{
|
|
141
|
+
items?: Array<{
|
|
142
|
+
text?: string;
|
|
143
|
+
content?: {
|
|
144
|
+
text?: string;
|
|
145
|
+
richtext?: {
|
|
146
|
+
text?: string;
|
|
147
|
+
};
|
|
148
|
+
rich_text?: {
|
|
149
|
+
text?: string;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
}>;
|
|
153
|
+
}>;
|
|
154
|
+
/** Draft.js content state for rich article content */
|
|
155
|
+
content_state?: {
|
|
156
|
+
blocks: Array<{
|
|
157
|
+
key: string;
|
|
158
|
+
type: string;
|
|
159
|
+
text: string;
|
|
160
|
+
data?: Record<string, unknown>;
|
|
161
|
+
entityRanges?: Array<{
|
|
162
|
+
key: number;
|
|
163
|
+
offset: number;
|
|
164
|
+
length: number;
|
|
165
|
+
}>;
|
|
166
|
+
inlineStyleRanges?: Array<{
|
|
167
|
+
offset: number;
|
|
168
|
+
length: number;
|
|
169
|
+
style: string;
|
|
170
|
+
}>;
|
|
171
|
+
}>;
|
|
172
|
+
entityMap?: Array<{
|
|
173
|
+
key: string;
|
|
174
|
+
value: {
|
|
175
|
+
type: string;
|
|
176
|
+
mutability: string;
|
|
177
|
+
data: Record<string, unknown>;
|
|
178
|
+
};
|
|
179
|
+
}> | Record<string, {
|
|
180
|
+
type: string;
|
|
181
|
+
mutability: string;
|
|
182
|
+
data: Record<string, unknown>;
|
|
183
|
+
}>;
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
plain_text?: string;
|
|
188
|
+
text?: string;
|
|
189
|
+
richtext?: {
|
|
190
|
+
text?: string;
|
|
191
|
+
};
|
|
192
|
+
rich_text?: {
|
|
193
|
+
text?: string;
|
|
194
|
+
};
|
|
195
|
+
body?: {
|
|
196
|
+
text?: string;
|
|
197
|
+
richtext?: {
|
|
198
|
+
text?: string;
|
|
199
|
+
};
|
|
200
|
+
rich_text?: {
|
|
201
|
+
text?: string;
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
content?: {
|
|
205
|
+
text?: string;
|
|
206
|
+
richtext?: {
|
|
207
|
+
text?: string;
|
|
208
|
+
};
|
|
209
|
+
rich_text?: {
|
|
210
|
+
text?: string;
|
|
211
|
+
};
|
|
212
|
+
items?: Array<{
|
|
213
|
+
text?: string;
|
|
214
|
+
content?: {
|
|
215
|
+
text?: string;
|
|
216
|
+
richtext?: {
|
|
217
|
+
text?: string;
|
|
218
|
+
};
|
|
219
|
+
rich_text?: {
|
|
220
|
+
text?: string;
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
}>;
|
|
224
|
+
};
|
|
225
|
+
sections?: Array<{
|
|
226
|
+
items?: Array<{
|
|
227
|
+
text?: string;
|
|
228
|
+
content?: {
|
|
229
|
+
text?: string;
|
|
230
|
+
richtext?: {
|
|
231
|
+
text?: string;
|
|
232
|
+
};
|
|
233
|
+
rich_text?: {
|
|
234
|
+
text?: string;
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
}>;
|
|
238
|
+
}>;
|
|
239
|
+
};
|
|
240
|
+
tweet?: GraphqlTweetResult;
|
|
241
|
+
quoted_status_result?: {
|
|
242
|
+
result?: GraphqlTweetResult;
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
export type TweetResult = {
|
|
246
|
+
success: true;
|
|
247
|
+
tweetId: string;
|
|
248
|
+
} | {
|
|
249
|
+
success: false;
|
|
250
|
+
error: string;
|
|
251
|
+
};
|
|
252
|
+
export type BookmarkMutationResult = {
|
|
253
|
+
success: true;
|
|
254
|
+
} | {
|
|
255
|
+
success: false;
|
|
256
|
+
error: string;
|
|
257
|
+
};
|
|
258
|
+
export type FollowMutationResult = {
|
|
259
|
+
success: true;
|
|
260
|
+
userId?: string;
|
|
261
|
+
username?: string;
|
|
262
|
+
} | {
|
|
263
|
+
success: false;
|
|
264
|
+
error: string;
|
|
265
|
+
};
|
|
266
|
+
export interface UploadMediaResult {
|
|
267
|
+
success: boolean;
|
|
268
|
+
mediaId?: string;
|
|
269
|
+
error?: string;
|
|
270
|
+
}
|
|
271
|
+
export interface TweetMedia {
|
|
272
|
+
type: 'photo' | 'video' | 'animated_gif';
|
|
273
|
+
url: string;
|
|
274
|
+
previewUrl?: string;
|
|
275
|
+
width?: number;
|
|
276
|
+
height?: number;
|
|
277
|
+
videoUrl?: string;
|
|
278
|
+
durationMs?: number;
|
|
279
|
+
}
|
|
280
|
+
export interface TweetData {
|
|
281
|
+
id: string;
|
|
282
|
+
text: string;
|
|
283
|
+
author: {
|
|
284
|
+
username: string;
|
|
285
|
+
name: string;
|
|
286
|
+
};
|
|
287
|
+
authorId?: string;
|
|
288
|
+
createdAt?: string;
|
|
289
|
+
replyCount?: number;
|
|
290
|
+
retweetCount?: number;
|
|
291
|
+
likeCount?: number;
|
|
292
|
+
conversationId?: string;
|
|
293
|
+
inReplyToStatusId?: string;
|
|
294
|
+
quotedTweet?: TweetData;
|
|
295
|
+
media?: TweetMedia[];
|
|
296
|
+
article?: {
|
|
297
|
+
title: string;
|
|
298
|
+
previewText?: string;
|
|
299
|
+
};
|
|
300
|
+
_raw?: GraphqlTweetResult;
|
|
301
|
+
}
|
|
302
|
+
export interface TweetWithMeta extends TweetData {
|
|
303
|
+
isThread: boolean;
|
|
304
|
+
threadPosition: 'root' | 'middle' | 'end' | 'standalone';
|
|
305
|
+
hasSelfReplies: boolean;
|
|
306
|
+
threadRootId: string | null;
|
|
307
|
+
}
|
|
308
|
+
export interface GetTweetResult {
|
|
309
|
+
success: boolean;
|
|
310
|
+
tweet?: TweetData;
|
|
311
|
+
error?: string;
|
|
312
|
+
}
|
|
313
|
+
export type SearchResult = {
|
|
314
|
+
success: true;
|
|
315
|
+
tweets: TweetData[];
|
|
316
|
+
/** Cursor for fetching the next page of results */
|
|
317
|
+
nextCursor?: string;
|
|
318
|
+
} | {
|
|
319
|
+
success: false;
|
|
320
|
+
error: string;
|
|
321
|
+
tweets?: TweetData[];
|
|
322
|
+
/** Cursor for fetching the next page of results */
|
|
323
|
+
nextCursor?: string;
|
|
324
|
+
};
|
|
325
|
+
export interface CurrentUserResult {
|
|
326
|
+
success: boolean;
|
|
327
|
+
user?: {
|
|
328
|
+
id: string;
|
|
329
|
+
username: string;
|
|
330
|
+
name: string;
|
|
331
|
+
};
|
|
332
|
+
error?: string;
|
|
333
|
+
}
|
|
334
|
+
export interface TwitterUser {
|
|
335
|
+
id: string;
|
|
336
|
+
username: string;
|
|
337
|
+
name: string;
|
|
338
|
+
description?: string;
|
|
339
|
+
followersCount?: number;
|
|
340
|
+
followingCount?: number;
|
|
341
|
+
isBlueVerified?: boolean;
|
|
342
|
+
profileImageUrl?: string;
|
|
343
|
+
createdAt?: string;
|
|
344
|
+
}
|
|
345
|
+
export interface FollowingResult {
|
|
346
|
+
success: boolean;
|
|
347
|
+
users?: TwitterUser[];
|
|
348
|
+
error?: string;
|
|
349
|
+
/** Cursor for fetching the next page of results */
|
|
350
|
+
nextCursor?: string;
|
|
351
|
+
}
|
|
352
|
+
export interface AboutAccountProfile {
|
|
353
|
+
accountBasedIn?: string;
|
|
354
|
+
source?: string;
|
|
355
|
+
createdCountryAccurate?: boolean;
|
|
356
|
+
locationAccurate?: boolean;
|
|
357
|
+
learnMoreUrl?: string;
|
|
358
|
+
}
|
|
359
|
+
export interface AboutAccountResult {
|
|
360
|
+
success: boolean;
|
|
361
|
+
aboutProfile?: AboutAccountProfile;
|
|
362
|
+
error?: string;
|
|
363
|
+
}
|
|
364
|
+
export interface TwitterClientOptions {
|
|
365
|
+
cookies: TwitterCookies;
|
|
366
|
+
userAgent?: string;
|
|
367
|
+
timeoutMs?: number;
|
|
368
|
+
quoteDepth?: number;
|
|
369
|
+
}
|
|
370
|
+
export interface TwitterList {
|
|
371
|
+
id: string;
|
|
372
|
+
name: string;
|
|
373
|
+
description?: string;
|
|
374
|
+
memberCount?: number;
|
|
375
|
+
subscriberCount?: number;
|
|
376
|
+
isPrivate?: boolean;
|
|
377
|
+
createdAt?: string;
|
|
378
|
+
owner?: {
|
|
379
|
+
id: string;
|
|
380
|
+
username: string;
|
|
381
|
+
name: string;
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
export interface ListsResult {
|
|
385
|
+
success: boolean;
|
|
386
|
+
lists?: TwitterList[];
|
|
387
|
+
error?: string;
|
|
388
|
+
}
|
|
389
|
+
export interface CreateTweetResponse {
|
|
390
|
+
data?: {
|
|
391
|
+
create_tweet?: {
|
|
392
|
+
tweet_results?: {
|
|
393
|
+
result?: {
|
|
394
|
+
rest_id?: string;
|
|
395
|
+
legacy?: {
|
|
396
|
+
full_text?: string;
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
};
|
|
402
|
+
errors?: Array<{
|
|
403
|
+
message: string;
|
|
404
|
+
code?: number;
|
|
405
|
+
}>;
|
|
406
|
+
}
|
|
407
|
+
//# sourceMappingURL=twitter-client-types.d.ts.map
|