dp-worker 0.1.23 → 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/ops.js +44 -0
- package/dist/bird/ops.js.map +1 -1
- 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 +308 -0
- package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.js +228 -0
- package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts +3 -3
- 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,358 @@
|
|
|
1
|
+
import { SETTINGS_NAME_REGEX, SETTINGS_SCREEN_NAME_REGEX, SETTINGS_USER_ID_REGEX, TWITTER_API_BASE, } from './twitter-client-constants.js';
|
|
2
|
+
import { buildFollowingFeatures } from './twitter-client-features.js';
|
|
3
|
+
import { extractCursorFromInstructions, parseUsersFromInstructions } from './twitter-client-utils.js';
|
|
4
|
+
export function withUsers(Base) {
|
|
5
|
+
class TwitterClientUsers extends Base {
|
|
6
|
+
// biome-ignore lint/complexity/noUselessConstructor lint/suspicious/noExplicitAny: TS mixin constructor requirement.
|
|
7
|
+
constructor(...args) {
|
|
8
|
+
super(...args);
|
|
9
|
+
}
|
|
10
|
+
async getFollowingQueryIds() {
|
|
11
|
+
const primary = await this.getQueryId('Following');
|
|
12
|
+
return Array.from(new Set([primary, 'BEkNpEt5pNETESoqMsTEGA']));
|
|
13
|
+
}
|
|
14
|
+
async getFollowersQueryIds() {
|
|
15
|
+
const primary = await this.getQueryId('Followers');
|
|
16
|
+
return Array.from(new Set([primary, 'kuFUYP9eV1FPoEy4N-pi7w']));
|
|
17
|
+
}
|
|
18
|
+
parseUsersFromRestResponse(users) {
|
|
19
|
+
return (users ?? [])
|
|
20
|
+
.map((u) => {
|
|
21
|
+
const id = typeof u.id_str === 'string' ? u.id_str : typeof u.id === 'number' ? String(u.id) : null;
|
|
22
|
+
const username = typeof u.screen_name === 'string' ? u.screen_name : null;
|
|
23
|
+
if (!id || !username) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
id,
|
|
28
|
+
username,
|
|
29
|
+
name: typeof u.name === 'string' && u.name.length > 0 ? u.name : username,
|
|
30
|
+
description: typeof u.description === 'string' ? u.description : undefined,
|
|
31
|
+
followersCount: typeof u.followers_count === 'number' ? u.followers_count : undefined,
|
|
32
|
+
followingCount: typeof u.friends_count === 'number' ? u.friends_count : undefined,
|
|
33
|
+
isBlueVerified: typeof u.verified === 'boolean' ? u.verified : undefined,
|
|
34
|
+
profileImageUrl: typeof u.profile_image_url_https === 'string' ? u.profile_image_url_https : undefined,
|
|
35
|
+
createdAt: typeof u.created_at === 'string' ? u.created_at : undefined,
|
|
36
|
+
};
|
|
37
|
+
})
|
|
38
|
+
.filter((u) => u !== null);
|
|
39
|
+
}
|
|
40
|
+
async getFollowersViaRest(userId, count, cursor) {
|
|
41
|
+
const params = new URLSearchParams({
|
|
42
|
+
user_id: userId,
|
|
43
|
+
count: String(count),
|
|
44
|
+
skip_status: 'true',
|
|
45
|
+
include_user_entities: 'false',
|
|
46
|
+
});
|
|
47
|
+
if (cursor) {
|
|
48
|
+
params.set('cursor', cursor);
|
|
49
|
+
}
|
|
50
|
+
const urls = [
|
|
51
|
+
`https://x.com/i/api/1.1/followers/list.json?${params.toString()}`,
|
|
52
|
+
`https://api.twitter.com/1.1/followers/list.json?${params.toString()}`,
|
|
53
|
+
];
|
|
54
|
+
let lastError;
|
|
55
|
+
for (const url of urls) {
|
|
56
|
+
try {
|
|
57
|
+
const response = await this.fetchWithTimeout(url, {
|
|
58
|
+
method: 'GET',
|
|
59
|
+
headers: this.getHeaders(),
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
const text = await response.text();
|
|
63
|
+
lastError = `HTTP ${response.status}: ${text.slice(0, 200)}`;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const data = (await response.json());
|
|
67
|
+
const users = this.parseUsersFromRestResponse(data.users);
|
|
68
|
+
const nextCursor = data.next_cursor_str && data.next_cursor_str !== '0' ? data.next_cursor_str : undefined;
|
|
69
|
+
return { success: true, users, nextCursor };
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { success: false, error: lastError ?? 'Unknown error fetching followers' };
|
|
76
|
+
}
|
|
77
|
+
async getFollowingViaRest(userId, count, cursor) {
|
|
78
|
+
const params = new URLSearchParams({
|
|
79
|
+
user_id: userId,
|
|
80
|
+
count: String(count),
|
|
81
|
+
skip_status: 'true',
|
|
82
|
+
include_user_entities: 'false',
|
|
83
|
+
});
|
|
84
|
+
if (cursor) {
|
|
85
|
+
params.set('cursor', cursor);
|
|
86
|
+
}
|
|
87
|
+
const urls = [
|
|
88
|
+
`https://x.com/i/api/1.1/friends/list.json?${params.toString()}`,
|
|
89
|
+
`https://api.twitter.com/1.1/friends/list.json?${params.toString()}`,
|
|
90
|
+
];
|
|
91
|
+
let lastError;
|
|
92
|
+
for (const url of urls) {
|
|
93
|
+
try {
|
|
94
|
+
const response = await this.fetchWithTimeout(url, {
|
|
95
|
+
method: 'GET',
|
|
96
|
+
headers: this.getHeaders(),
|
|
97
|
+
});
|
|
98
|
+
if (!response.ok) {
|
|
99
|
+
const text = await response.text();
|
|
100
|
+
lastError = `HTTP ${response.status}: ${text.slice(0, 200)}`;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const data = (await response.json());
|
|
104
|
+
const users = this.parseUsersFromRestResponse(data.users);
|
|
105
|
+
const nextCursor = data.next_cursor_str && data.next_cursor_str !== '0' ? data.next_cursor_str : undefined;
|
|
106
|
+
return { success: true, users, nextCursor };
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { success: false, error: lastError ?? 'Unknown error fetching following' };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Fetch the account associated with the current cookies
|
|
116
|
+
*/
|
|
117
|
+
async getCurrentUser() {
|
|
118
|
+
const candidateUrls = [
|
|
119
|
+
'https://x.com/i/api/account/settings.json',
|
|
120
|
+
'https://api.twitter.com/1.1/account/settings.json',
|
|
121
|
+
'https://x.com/i/api/account/verify_credentials.json?skip_status=true&include_entities=false',
|
|
122
|
+
'https://api.twitter.com/1.1/account/verify_credentials.json?skip_status=true&include_entities=false',
|
|
123
|
+
];
|
|
124
|
+
let lastError;
|
|
125
|
+
for (const url of candidateUrls) {
|
|
126
|
+
try {
|
|
127
|
+
const response = await this.fetchWithTimeout(url, {
|
|
128
|
+
method: 'GET',
|
|
129
|
+
headers: this.getHeaders(),
|
|
130
|
+
});
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
const text = await response.text();
|
|
133
|
+
lastError = `HTTP ${response.status}: ${text.slice(0, 200)}`;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
// biome-ignore lint/suspicious/noExplicitAny: Twitter API response is dynamic here
|
|
137
|
+
let data;
|
|
138
|
+
try {
|
|
139
|
+
data = await response.json();
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const username = typeof data?.screen_name === 'string'
|
|
146
|
+
? data.screen_name
|
|
147
|
+
: typeof data?.user?.screen_name === 'string'
|
|
148
|
+
? data.user.screen_name
|
|
149
|
+
: null;
|
|
150
|
+
const name = typeof data?.name === 'string'
|
|
151
|
+
? data.name
|
|
152
|
+
: typeof data?.user?.name === 'string'
|
|
153
|
+
? data.user.name
|
|
154
|
+
: (username ?? '');
|
|
155
|
+
const userId = typeof data?.user_id === 'string'
|
|
156
|
+
? data.user_id
|
|
157
|
+
: typeof data?.user_id_str === 'string'
|
|
158
|
+
? data.user_id_str
|
|
159
|
+
: typeof data?.user?.id_str === 'string'
|
|
160
|
+
? data.user.id_str
|
|
161
|
+
: typeof data?.user?.id === 'string'
|
|
162
|
+
? data.user.id
|
|
163
|
+
: null;
|
|
164
|
+
if (username && userId) {
|
|
165
|
+
this.clientUserId = userId;
|
|
166
|
+
return {
|
|
167
|
+
success: true,
|
|
168
|
+
user: {
|
|
169
|
+
id: userId,
|
|
170
|
+
username,
|
|
171
|
+
name: name || username,
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
lastError = 'Could not determine current user from response';
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Fallback: scrape the authenticated settings page (HTML) for screen_name/user_id
|
|
182
|
+
const profilePages = ['https://x.com/settings/account', 'https://twitter.com/settings/account'];
|
|
183
|
+
for (const page of profilePages) {
|
|
184
|
+
try {
|
|
185
|
+
const response = await this.fetchWithTimeout(page, {
|
|
186
|
+
headers: {
|
|
187
|
+
cookie: this.cookieHeader,
|
|
188
|
+
'user-agent': this.userAgent,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
if (!response.ok) {
|
|
192
|
+
lastError = `HTTP ${response.status} (settings page)`;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const html = await response.text();
|
|
196
|
+
const usernameMatch = SETTINGS_SCREEN_NAME_REGEX.exec(html);
|
|
197
|
+
const idMatch = SETTINGS_USER_ID_REGEX.exec(html);
|
|
198
|
+
const nameMatch = SETTINGS_NAME_REGEX.exec(html);
|
|
199
|
+
const username = usernameMatch?.[1];
|
|
200
|
+
const userId = idMatch?.[1];
|
|
201
|
+
const name = nameMatch?.[1]?.replace(/\\"/g, '"');
|
|
202
|
+
if (username && userId) {
|
|
203
|
+
return {
|
|
204
|
+
success: true,
|
|
205
|
+
user: {
|
|
206
|
+
id: userId,
|
|
207
|
+
username,
|
|
208
|
+
name: name || username,
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
lastError = 'Could not parse settings page for user info';
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
success: false,
|
|
220
|
+
error: lastError ?? 'Unknown error fetching current user',
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get users that a user is following
|
|
225
|
+
*/
|
|
226
|
+
async getFollowing(userId, count = 20, cursor) {
|
|
227
|
+
const variables = {
|
|
228
|
+
userId,
|
|
229
|
+
count,
|
|
230
|
+
includePromotedContent: false,
|
|
231
|
+
};
|
|
232
|
+
if (cursor) {
|
|
233
|
+
variables.cursor = cursor;
|
|
234
|
+
}
|
|
235
|
+
const features = buildFollowingFeatures();
|
|
236
|
+
const params = new URLSearchParams({
|
|
237
|
+
variables: JSON.stringify(variables),
|
|
238
|
+
features: JSON.stringify(features),
|
|
239
|
+
});
|
|
240
|
+
const tryOnce = async () => {
|
|
241
|
+
let lastError;
|
|
242
|
+
let had404 = false;
|
|
243
|
+
const queryIds = await this.getFollowingQueryIds();
|
|
244
|
+
for (const queryId of queryIds) {
|
|
245
|
+
const url = `${TWITTER_API_BASE}/${queryId}/Following?${params.toString()}`;
|
|
246
|
+
try {
|
|
247
|
+
const response = await this.fetchWithTimeout(url, {
|
|
248
|
+
method: 'GET',
|
|
249
|
+
headers: this.getHeaders(),
|
|
250
|
+
});
|
|
251
|
+
if (response.status === 404) {
|
|
252
|
+
had404 = true;
|
|
253
|
+
lastError = `HTTP ${response.status}`;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (!response.ok) {
|
|
257
|
+
const text = await response.text();
|
|
258
|
+
return { success: false, error: `HTTP ${response.status}: ${text.slice(0, 200)}`, had404 };
|
|
259
|
+
}
|
|
260
|
+
const data = (await response.json());
|
|
261
|
+
if (data.errors && data.errors.length > 0) {
|
|
262
|
+
return { success: false, error: data.errors.map((e) => e.message).join(', '), had404 };
|
|
263
|
+
}
|
|
264
|
+
const instructions = data.data?.user?.result?.timeline?.timeline?.instructions;
|
|
265
|
+
const users = parseUsersFromInstructions(instructions);
|
|
266
|
+
const nextCursor = extractCursorFromInstructions(instructions);
|
|
267
|
+
return { success: true, users, nextCursor, had404 };
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return { success: false, error: lastError ?? 'Unknown error fetching following', had404 };
|
|
274
|
+
};
|
|
275
|
+
const { result, refreshed } = await this.withRefreshedQueryIdsOn404(tryOnce);
|
|
276
|
+
if (result.success) {
|
|
277
|
+
return { success: true, users: result.users, nextCursor: result.nextCursor };
|
|
278
|
+
}
|
|
279
|
+
if (refreshed) {
|
|
280
|
+
// GraphQL Following can also return 404 (queryId churn / endpoint flakiness).
|
|
281
|
+
// Fallback to the internal v1.1 REST endpoint used by the web client (cookie-auth; no dev API key).
|
|
282
|
+
const restAttempt = await this.getFollowingViaRest(userId, count, cursor);
|
|
283
|
+
if (restAttempt.success) {
|
|
284
|
+
return restAttempt;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return { success: false, error: result.error };
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Get users that follow a user
|
|
291
|
+
*/
|
|
292
|
+
async getFollowers(userId, count = 20, cursor) {
|
|
293
|
+
const variables = {
|
|
294
|
+
userId,
|
|
295
|
+
count,
|
|
296
|
+
includePromotedContent: false,
|
|
297
|
+
};
|
|
298
|
+
if (cursor) {
|
|
299
|
+
variables.cursor = cursor;
|
|
300
|
+
}
|
|
301
|
+
const features = buildFollowingFeatures();
|
|
302
|
+
const params = new URLSearchParams({
|
|
303
|
+
variables: JSON.stringify(variables),
|
|
304
|
+
features: JSON.stringify(features),
|
|
305
|
+
});
|
|
306
|
+
const tryOnce = async () => {
|
|
307
|
+
let lastError;
|
|
308
|
+
let had404 = false;
|
|
309
|
+
const queryIds = await this.getFollowersQueryIds();
|
|
310
|
+
for (const queryId of queryIds) {
|
|
311
|
+
const url = `${TWITTER_API_BASE}/${queryId}/Followers?${params.toString()}`;
|
|
312
|
+
try {
|
|
313
|
+
const response = await this.fetchWithTimeout(url, {
|
|
314
|
+
method: 'GET',
|
|
315
|
+
headers: this.getHeaders(),
|
|
316
|
+
});
|
|
317
|
+
if (response.status === 404) {
|
|
318
|
+
had404 = true;
|
|
319
|
+
lastError = `HTTP ${response.status}`;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (!response.ok) {
|
|
323
|
+
const text = await response.text();
|
|
324
|
+
return { success: false, error: `HTTP ${response.status}: ${text.slice(0, 200)}`, had404 };
|
|
325
|
+
}
|
|
326
|
+
const data = (await response.json());
|
|
327
|
+
if (data.errors && data.errors.length > 0) {
|
|
328
|
+
return { success: false, error: data.errors.map((e) => e.message).join(', '), had404 };
|
|
329
|
+
}
|
|
330
|
+
const instructions = data.data?.user?.result?.timeline?.timeline?.instructions;
|
|
331
|
+
const users = parseUsersFromInstructions(instructions);
|
|
332
|
+
const nextCursor = extractCursorFromInstructions(instructions);
|
|
333
|
+
return { success: true, users, nextCursor, had404 };
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
lastError = error instanceof Error ? error.message : String(error);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return { success: false, error: lastError ?? 'Unknown error fetching followers', had404 };
|
|
340
|
+
};
|
|
341
|
+
const { result, refreshed } = await this.withRefreshedQueryIdsOn404(tryOnce);
|
|
342
|
+
if (result.success) {
|
|
343
|
+
return { success: true, users: result.users, nextCursor: result.nextCursor };
|
|
344
|
+
}
|
|
345
|
+
if (refreshed) {
|
|
346
|
+
// GraphQL Followers regularly returns 404 (queryId churn / endpoint flakiness).
|
|
347
|
+
// Fallback to the internal v1.1 REST endpoint used by the web client (cookie-auth; no dev API key).
|
|
348
|
+
const restAttempt = await this.getFollowersViaRest(userId, count, cursor);
|
|
349
|
+
if (restAttempt.success) {
|
|
350
|
+
return restAttempt;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return { success: false, error: result.error };
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return TwitterClientUsers;
|
|
357
|
+
}
|
|
358
|
+
//# sourceMappingURL=twitter-client-users.js.map
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { GraphqlTweetResult, TweetData, TweetMedia, TwitterUser } from './twitter-client-types.js';
|
|
2
|
+
export declare function normalizeQuoteDepth(value?: number): number;
|
|
3
|
+
export declare function firstText(...values: Array<string | undefined | null>): string | undefined;
|
|
4
|
+
export declare function collectTextFields(value: unknown, keys: Set<string>, output: string[]): void;
|
|
5
|
+
export declare function uniqueOrdered(values: string[]): string[];
|
|
6
|
+
/** Inline style range for text formatting (Bold, Italic, etc.) */
|
|
7
|
+
interface InlineStyleRange {
|
|
8
|
+
offset: number;
|
|
9
|
+
length: number;
|
|
10
|
+
style: string;
|
|
11
|
+
}
|
|
12
|
+
/** Entity range linking a portion of text to an entity in entityMap */
|
|
13
|
+
interface EntityRange {
|
|
14
|
+
key: number;
|
|
15
|
+
offset: number;
|
|
16
|
+
length: number;
|
|
17
|
+
}
|
|
18
|
+
/** A content block in Draft.js format */
|
|
19
|
+
interface ContentBlock {
|
|
20
|
+
key: string;
|
|
21
|
+
type: string;
|
|
22
|
+
text: string;
|
|
23
|
+
data?: {
|
|
24
|
+
mentions?: Array<{
|
|
25
|
+
fromIndex: number;
|
|
26
|
+
toIndex: number;
|
|
27
|
+
text: string;
|
|
28
|
+
}>;
|
|
29
|
+
};
|
|
30
|
+
entityRanges?: EntityRange[];
|
|
31
|
+
inlineStyleRanges?: InlineStyleRange[];
|
|
32
|
+
}
|
|
33
|
+
/** Entity data for different entity types */
|
|
34
|
+
interface EntityValue {
|
|
35
|
+
type: string;
|
|
36
|
+
mutability: string;
|
|
37
|
+
data: {
|
|
38
|
+
markdown?: string;
|
|
39
|
+
url?: string;
|
|
40
|
+
tweetId?: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Entity map entry */
|
|
44
|
+
interface EntityMapEntry {
|
|
45
|
+
key: string;
|
|
46
|
+
value: EntityValue;
|
|
47
|
+
}
|
|
48
|
+
/** Draft.js content state structure */
|
|
49
|
+
interface ContentState {
|
|
50
|
+
blocks: ContentBlock[];
|
|
51
|
+
entityMap?: Array<EntityMapEntry> | Record<string, EntityValue>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Renders a Draft.js content_state into readable markdown/text format.
|
|
55
|
+
* Handles blocks (paragraphs, headers, lists) and entities (code blocks, links, tweets, dividers).
|
|
56
|
+
*/
|
|
57
|
+
export declare function renderContentState(contentState: ContentState | undefined): string | undefined;
|
|
58
|
+
export declare function extractArticleText(result: GraphqlTweetResult | undefined): string | undefined;
|
|
59
|
+
export declare function extractNoteTweetText(result: GraphqlTweetResult | undefined): string | undefined;
|
|
60
|
+
export declare function extractTweetText(result: GraphqlTweetResult | undefined): string | undefined;
|
|
61
|
+
export declare function extractArticleMetadata(result: GraphqlTweetResult | undefined): {
|
|
62
|
+
title: string;
|
|
63
|
+
previewText?: string;
|
|
64
|
+
} | undefined;
|
|
65
|
+
export declare function extractMedia(result: GraphqlTweetResult | undefined): TweetMedia[] | undefined;
|
|
66
|
+
export declare function unwrapTweetResult(result: GraphqlTweetResult | undefined): GraphqlTweetResult | undefined;
|
|
67
|
+
export interface MapTweetResultOptions {
|
|
68
|
+
quoteDepth: number;
|
|
69
|
+
includeRaw?: boolean;
|
|
70
|
+
}
|
|
71
|
+
export declare function mapTweetResult(result: GraphqlTweetResult | undefined, quoteDepthOrOptions: number | MapTweetResultOptions): TweetData | undefined;
|
|
72
|
+
export declare function findTweetInInstructions(instructions: Array<{
|
|
73
|
+
entries?: Array<{
|
|
74
|
+
content?: {
|
|
75
|
+
itemContent?: {
|
|
76
|
+
tweet_results?: {
|
|
77
|
+
result?: GraphqlTweetResult;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
}>;
|
|
82
|
+
}> | undefined, tweetId: string): GraphqlTweetResult | undefined;
|
|
83
|
+
export declare function collectTweetResultsFromEntry(entry: {
|
|
84
|
+
content?: {
|
|
85
|
+
itemContent?: {
|
|
86
|
+
tweet_results?: {
|
|
87
|
+
result?: GraphqlTweetResult;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
item?: {
|
|
91
|
+
itemContent?: {
|
|
92
|
+
tweet_results?: {
|
|
93
|
+
result?: GraphqlTweetResult;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
items?: Array<{
|
|
98
|
+
item?: {
|
|
99
|
+
itemContent?: {
|
|
100
|
+
tweet_results?: {
|
|
101
|
+
result?: GraphqlTweetResult;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
itemContent?: {
|
|
106
|
+
tweet_results?: {
|
|
107
|
+
result?: GraphqlTweetResult;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
content?: {
|
|
111
|
+
itemContent?: {
|
|
112
|
+
tweet_results?: {
|
|
113
|
+
result?: GraphqlTweetResult;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
}>;
|
|
118
|
+
};
|
|
119
|
+
}): GraphqlTweetResult[];
|
|
120
|
+
export interface ParseTweetsOptions {
|
|
121
|
+
quoteDepth: number;
|
|
122
|
+
includeRaw?: boolean;
|
|
123
|
+
}
|
|
124
|
+
export declare function parseTweetsFromInstructions(instructions: Array<{
|
|
125
|
+
entries?: Array<{
|
|
126
|
+
content?: {
|
|
127
|
+
itemContent?: {
|
|
128
|
+
tweet_results?: {
|
|
129
|
+
result?: GraphqlTweetResult;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
item?: {
|
|
133
|
+
itemContent?: {
|
|
134
|
+
tweet_results?: {
|
|
135
|
+
result?: GraphqlTweetResult;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
items?: Array<{
|
|
140
|
+
item?: {
|
|
141
|
+
itemContent?: {
|
|
142
|
+
tweet_results?: {
|
|
143
|
+
result?: GraphqlTweetResult;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
itemContent?: {
|
|
148
|
+
tweet_results?: {
|
|
149
|
+
result?: GraphqlTweetResult;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
content?: {
|
|
153
|
+
itemContent?: {
|
|
154
|
+
tweet_results?: {
|
|
155
|
+
result?: GraphqlTweetResult;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
}>;
|
|
160
|
+
};
|
|
161
|
+
}>;
|
|
162
|
+
}> | undefined, quoteDepthOrOptions: number | ParseTweetsOptions): TweetData[];
|
|
163
|
+
export declare function extractCursorFromInstructions(instructions: Array<{
|
|
164
|
+
entries?: Array<{
|
|
165
|
+
content?: unknown;
|
|
166
|
+
}>;
|
|
167
|
+
}> | undefined, cursorType?: string): string | undefined;
|
|
168
|
+
export declare function parseUsersFromInstructions(instructions: Array<{
|
|
169
|
+
type?: string;
|
|
170
|
+
entries?: Array<unknown>;
|
|
171
|
+
}> | undefined): TwitterUser[];
|
|
172
|
+
export {};
|
|
173
|
+
//# sourceMappingURL=twitter-client-utils.d.ts.map
|