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.
Files changed (120) hide show
  1. package/dist/bird/ops.js +44 -0
  2. package/dist/bird/ops.js.map +1 -1
  3. package/dist/bird/sidecar-entry.js +16 -2
  4. package/dist/bird/sidecar-entry.js.map +1 -1
  5. package/dist/chrome-extension/omni-flow/manifest.json +1 -1
  6. package/node_modules/dp-shared/dist/bird-contracts.d.ts +308 -0
  7. package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
  8. package/node_modules/dp-shared/dist/bird-contracts.js +228 -0
  9. package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
  10. package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts +3 -3
  11. package/package.json +2 -2
  12. package/vendor/bird/LICENSE +21 -0
  13. package/vendor/bird/README.md +58 -0
  14. package/vendor/bird/dist/cli/pagination.d.ts +35 -0
  15. package/vendor/bird/dist/cli/pagination.js +43 -0
  16. package/vendor/bird/dist/cli/program.d.ts +5 -0
  17. package/vendor/bird/dist/cli/program.js +113 -0
  18. package/vendor/bird/dist/cli/shared.d.ts +77 -0
  19. package/vendor/bird/dist/cli/shared.js +327 -0
  20. package/vendor/bird/dist/cli.d.ts +12 -0
  21. package/vendor/bird/dist/cli.js +29 -0
  22. package/vendor/bird/dist/commands/bookmarks.d.ts +4 -0
  23. package/vendor/bird/dist/commands/bookmarks.js +189 -0
  24. package/vendor/bird/dist/commands/check.d.ts +4 -0
  25. package/vendor/bird/dist/commands/check.js +43 -0
  26. package/vendor/bird/dist/commands/follow.d.ts +4 -0
  27. package/vendor/bird/dist/commands/follow.js +91 -0
  28. package/vendor/bird/dist/commands/help.d.ts +4 -0
  29. package/vendor/bird/dist/commands/help.js +19 -0
  30. package/vendor/bird/dist/commands/home.d.ts +4 -0
  31. package/vendor/bird/dist/commands/home.js +43 -0
  32. package/vendor/bird/dist/commands/lists.d.ts +4 -0
  33. package/vendor/bird/dist/commands/lists.js +125 -0
  34. package/vendor/bird/dist/commands/news.d.ts +4 -0
  35. package/vendor/bird/dist/commands/news.js +131 -0
  36. package/vendor/bird/dist/commands/post.d.ts +4 -0
  37. package/vendor/bird/dist/commands/post.js +101 -0
  38. package/vendor/bird/dist/commands/query-ids.d.ts +4 -0
  39. package/vendor/bird/dist/commands/query-ids.js +80 -0
  40. package/vendor/bird/dist/commands/read.d.ts +4 -0
  41. package/vendor/bird/dist/commands/read.js +152 -0
  42. package/vendor/bird/dist/commands/search.d.ts +4 -0
  43. package/vendor/bird/dist/commands/search.js +115 -0
  44. package/vendor/bird/dist/commands/unbookmark.d.ts +4 -0
  45. package/vendor/bird/dist/commands/unbookmark.js +36 -0
  46. package/vendor/bird/dist/commands/user-tweets.d.ts +4 -0
  47. package/vendor/bird/dist/commands/user-tweets.js +109 -0
  48. package/vendor/bird/dist/commands/users.d.ts +4 -0
  49. package/vendor/bird/dist/commands/users.js +295 -0
  50. package/vendor/bird/dist/index.d.ts +2 -0
  51. package/vendor/bird/dist/index.js +2 -0
  52. package/vendor/bird/dist/lib/cli-args.d.ts +7 -0
  53. package/vendor/bird/dist/lib/cli-args.js +25 -0
  54. package/vendor/bird/dist/lib/cookies.d.ts +31 -0
  55. package/vendor/bird/dist/lib/cookies.js +81 -0
  56. package/vendor/bird/dist/lib/extract-bookmark-folder-id.d.ts +2 -0
  57. package/vendor/bird/dist/lib/extract-bookmark-folder-id.js +20 -0
  58. package/vendor/bird/dist/lib/extract-list-id.d.ts +2 -0
  59. package/vendor/bird/dist/lib/extract-list-id.js +19 -0
  60. package/vendor/bird/dist/lib/extract-tweet-id.d.ts +2 -0
  61. package/vendor/bird/dist/lib/extract-tweet-id.js +14 -0
  62. package/vendor/bird/dist/lib/features.json +17 -0
  63. package/vendor/bird/dist/lib/index.d.ts +10 -0
  64. package/vendor/bird/dist/lib/index.js +4 -0
  65. package/vendor/bird/dist/lib/normalize-handle.d.ts +6 -0
  66. package/vendor/bird/dist/lib/normalize-handle.js +31 -0
  67. package/vendor/bird/dist/lib/output.d.ts +29 -0
  68. package/vendor/bird/dist/lib/output.js +88 -0
  69. package/vendor/bird/dist/lib/paginate-cursor.d.ts +27 -0
  70. package/vendor/bird/dist/lib/paginate-cursor.js +37 -0
  71. package/vendor/bird/dist/lib/query-ids.json +20 -0
  72. package/vendor/bird/dist/lib/runtime-features.d.ts +19 -0
  73. package/vendor/bird/dist/lib/runtime-features.js +151 -0
  74. package/vendor/bird/dist/lib/runtime-query-ids.d.ts +33 -0
  75. package/vendor/bird/dist/lib/runtime-query-ids.js +264 -0
  76. package/vendor/bird/dist/lib/thread-filters.d.ts +8 -0
  77. package/vendor/bird/dist/lib/thread-filters.js +124 -0
  78. package/vendor/bird/dist/lib/twitter-client-base.d.ts +38 -0
  79. package/vendor/bird/dist/lib/twitter-client-base.js +129 -0
  80. package/vendor/bird/dist/lib/twitter-client-bookmarks.d.ts +7 -0
  81. package/vendor/bird/dist/lib/twitter-client-bookmarks.js +61 -0
  82. package/vendor/bird/dist/lib/twitter-client-constants.d.ts +43 -0
  83. package/vendor/bird/dist/lib/twitter-client-constants.js +50 -0
  84. package/vendor/bird/dist/lib/twitter-client-engagement.d.ts +16 -0
  85. package/vendor/bird/dist/lib/twitter-client-engagement.js +81 -0
  86. package/vendor/bird/dist/lib/twitter-client-features.d.ts +14 -0
  87. package/vendor/bird/dist/lib/twitter-client-features.js +347 -0
  88. package/vendor/bird/dist/lib/twitter-client-follow.d.ts +8 -0
  89. package/vendor/bird/dist/lib/twitter-client-follow.js +178 -0
  90. package/vendor/bird/dist/lib/twitter-client-home.d.ts +13 -0
  91. package/vendor/bird/dist/lib/twitter-client-home.js +138 -0
  92. package/vendor/bird/dist/lib/twitter-client-lists.d.ts +11 -0
  93. package/vendor/bird/dist/lib/twitter-client-lists.js +321 -0
  94. package/vendor/bird/dist/lib/twitter-client-media.d.ts +11 -0
  95. package/vendor/bird/dist/lib/twitter-client-media.js +136 -0
  96. package/vendor/bird/dist/lib/twitter-client-news.d.ts +47 -0
  97. package/vendor/bird/dist/lib/twitter-client-news.js +283 -0
  98. package/vendor/bird/dist/lib/twitter-client-posting.d.ts +8 -0
  99. package/vendor/bird/dist/lib/twitter-client-posting.js +218 -0
  100. package/vendor/bird/dist/lib/twitter-client-search.d.ts +19 -0
  101. package/vendor/bird/dist/lib/twitter-client-search.js +157 -0
  102. package/vendor/bird/dist/lib/twitter-client-timelines.d.ts +23 -0
  103. package/vendor/bird/dist/lib/twitter-client-timelines.js +471 -0
  104. package/vendor/bird/dist/lib/twitter-client-tweet-detail.d.ts +25 -0
  105. package/vendor/bird/dist/lib/twitter-client-tweet-detail.js +295 -0
  106. package/vendor/bird/dist/lib/twitter-client-types.d.ts +407 -0
  107. package/vendor/bird/dist/lib/twitter-client-types.js +2 -0
  108. package/vendor/bird/dist/lib/twitter-client-user-lookup.d.ts +16 -0
  109. package/vendor/bird/dist/lib/twitter-client-user-lookup.js +224 -0
  110. package/vendor/bird/dist/lib/twitter-client-user-tweets.d.ts +22 -0
  111. package/vendor/bird/dist/lib/twitter-client-user-tweets.js +154 -0
  112. package/vendor/bird/dist/lib/twitter-client-users.d.ts +9 -0
  113. package/vendor/bird/dist/lib/twitter-client-users.js +358 -0
  114. package/vendor/bird/dist/lib/twitter-client-utils.d.ts +173 -0
  115. package/vendor/bird/dist/lib/twitter-client-utils.js +511 -0
  116. package/vendor/bird/dist/lib/twitter-client.d.ts +23 -0
  117. package/vendor/bird/dist/lib/twitter-client.js +21 -0
  118. package/vendor/bird/dist/lib/version.d.ts +6 -0
  119. package/vendor/bird/dist/lib/version.js +174 -0
  120. package/vendor/bird/upstream-package.json +61 -0
@@ -0,0 +1,16 @@
1
+ import type { AbstractConstructor, Mixin, TwitterClientBase } from './twitter-client-base.js';
2
+ import type { AboutAccountResult } from './twitter-client-types.js';
3
+ /** Result of username to userId lookup */
4
+ export interface UserLookupResult {
5
+ success: boolean;
6
+ userId?: string;
7
+ username?: string;
8
+ name?: string;
9
+ error?: string;
10
+ }
11
+ export interface TwitterClientUserLookupMethods {
12
+ getUserIdByUsername(username: string): Promise<UserLookupResult>;
13
+ getUserAboutAccount(username: string): Promise<AboutAccountResult>;
14
+ }
15
+ export declare function withUserLookup<TBase extends AbstractConstructor<TwitterClientBase>>(Base: TBase): Mixin<TBase, TwitterClientUserLookupMethods>;
16
+ //# sourceMappingURL=twitter-client-user-lookup.d.ts.map
@@ -0,0 +1,224 @@
1
+ import { normalizeHandle } from './normalize-handle.js';
2
+ import { TWITTER_API_BASE } from './twitter-client-constants.js';
3
+ export function withUserLookup(Base) {
4
+ class TwitterClientUserLookup extends Base {
5
+ // biome-ignore lint/complexity/noUselessConstructor lint/suspicious/noExplicitAny: TS mixin constructor requirement.
6
+ constructor(...args) {
7
+ super(...args);
8
+ }
9
+ async getUserByScreenNameGraphQL(screenName) {
10
+ // UserByScreenName query IDs observed from web client
11
+ const queryIds = ['xc8f1g7BYqr6VTzTbvNlGw', 'qW5u-DAuXpMEG0zA1F7UGQ', 'sLVLhk0bGj3MVFEKTdax1w'];
12
+ const variables = {
13
+ screen_name: screenName,
14
+ withSafetyModeUserFields: true,
15
+ };
16
+ const features = {
17
+ hidden_profile_subscriptions_enabled: true,
18
+ hidden_profile_likes_enabled: true,
19
+ rweb_tipjar_consumption_enabled: true,
20
+ responsive_web_graphql_exclude_directive_enabled: true,
21
+ verified_phone_label_enabled: false,
22
+ subscriptions_verification_info_is_identity_verified_enabled: true,
23
+ subscriptions_verification_info_verified_since_enabled: true,
24
+ highlights_tweets_tab_ui_enabled: true,
25
+ responsive_web_twitter_article_notes_tab_enabled: true,
26
+ subscriptions_feature_can_gift_premium: true,
27
+ creator_subscriptions_tweet_preview_api_enabled: true,
28
+ responsive_web_graphql_skip_user_profile_image_extensions_enabled: false,
29
+ responsive_web_graphql_timeline_navigation_enabled: true,
30
+ blue_business_profile_image_shape_enabled: true,
31
+ };
32
+ const fieldToggles = {
33
+ withAuxiliaryUserLabels: false,
34
+ };
35
+ const params = new URLSearchParams({
36
+ variables: JSON.stringify(variables),
37
+ features: JSON.stringify(features),
38
+ fieldToggles: JSON.stringify(fieldToggles),
39
+ });
40
+ let lastError;
41
+ for (const queryId of queryIds) {
42
+ const url = `${TWITTER_API_BASE}/${queryId}/UserByScreenName?${params.toString()}`;
43
+ try {
44
+ const response = await this.fetchWithTimeout(url, {
45
+ method: 'GET',
46
+ headers: this.getHeaders(),
47
+ });
48
+ if (!response.ok) {
49
+ const text = await response.text();
50
+ if (response.status === 404) {
51
+ // Try next query ID
52
+ lastError = `HTTP ${response.status}`;
53
+ continue;
54
+ }
55
+ lastError = `HTTP ${response.status}: ${text.slice(0, 200)}`;
56
+ continue;
57
+ }
58
+ const data = (await response.json());
59
+ // Check for user not found
60
+ if (data.data?.user?.result?.__typename === 'UserUnavailable') {
61
+ return { success: false, error: `User @${screenName} not found or unavailable` };
62
+ }
63
+ const userResult = data.data?.user?.result;
64
+ const userId = userResult?.rest_id;
65
+ const username = userResult?.legacy?.screen_name ?? userResult?.core?.screen_name;
66
+ const name = userResult?.legacy?.name ?? userResult?.core?.name;
67
+ if (userId && username) {
68
+ return {
69
+ success: true,
70
+ userId,
71
+ username,
72
+ name,
73
+ };
74
+ }
75
+ if (data.errors && data.errors.length > 0) {
76
+ lastError = data.errors.map((e) => e.message).join(', ');
77
+ continue;
78
+ }
79
+ lastError = 'Could not parse user data from response';
80
+ }
81
+ catch (error) {
82
+ lastError = error instanceof Error ? error.message : String(error);
83
+ }
84
+ }
85
+ return { success: false, error: lastError ?? 'Unknown error looking up user' };
86
+ }
87
+ /**
88
+ * Look up a user's ID by their username/handle.
89
+ * Uses GraphQL UserByScreenName first, then falls back to REST on transient failures.
90
+ */
91
+ async getUserIdByUsername(username) {
92
+ const cleanUsername = normalizeHandle(username);
93
+ if (!cleanUsername) {
94
+ return { success: false, error: `Invalid username: ${username}` };
95
+ }
96
+ const graphqlResult = await this.getUserByScreenNameGraphQL(cleanUsername);
97
+ if (graphqlResult.success) {
98
+ return graphqlResult;
99
+ }
100
+ // If GraphQL definitively says user is unavailable, don't retry with REST
101
+ if (graphqlResult.error?.includes('not found or unavailable')) {
102
+ return graphqlResult;
103
+ }
104
+ // Fallback to REST API for transient GraphQL errors
105
+ const urls = [
106
+ `https://x.com/i/api/1.1/users/show.json?screen_name=${encodeURIComponent(cleanUsername)}`,
107
+ `https://api.twitter.com/1.1/users/show.json?screen_name=${encodeURIComponent(cleanUsername)}`,
108
+ ];
109
+ let lastError = graphqlResult.error;
110
+ for (const url of urls) {
111
+ try {
112
+ const response = await this.fetchWithTimeout(url, {
113
+ method: 'GET',
114
+ headers: this.getHeaders(),
115
+ });
116
+ if (!response.ok) {
117
+ const text = await response.text();
118
+ if (response.status === 404) {
119
+ return { success: false, error: `User @${cleanUsername} not found` };
120
+ }
121
+ lastError = `HTTP ${response.status}: ${text.slice(0, 200)}`;
122
+ continue;
123
+ }
124
+ const data = (await response.json());
125
+ const userId = data.id_str ?? (data.id ? String(data.id) : null);
126
+ if (!userId) {
127
+ lastError = 'Could not parse user ID from response';
128
+ continue;
129
+ }
130
+ return {
131
+ success: true,
132
+ userId,
133
+ username: data.screen_name ?? cleanUsername,
134
+ name: data.name,
135
+ };
136
+ }
137
+ catch (error) {
138
+ lastError = error instanceof Error ? error.message : String(error);
139
+ }
140
+ }
141
+ return { success: false, error: lastError ?? 'Unknown error looking up user' };
142
+ }
143
+ async getAboutAccountQueryIds() {
144
+ const primary = await this.getQueryId('AboutAccountQuery');
145
+ return Array.from(new Set([primary, 'zs_jFPFT78rBpXv9Z3U2YQ']));
146
+ }
147
+ /**
148
+ * Get account origin and location information for a user.
149
+ * Returns data from Twitter's "About this account" feature.
150
+ */
151
+ async getUserAboutAccount(username) {
152
+ const cleanUsername = normalizeHandle(username);
153
+ if (!cleanUsername) {
154
+ return { success: false, error: `Invalid username: ${username}` };
155
+ }
156
+ const variables = {
157
+ screenName: cleanUsername,
158
+ };
159
+ const params = new URLSearchParams({
160
+ variables: JSON.stringify(variables),
161
+ });
162
+ const tryOnce = async () => {
163
+ let lastError;
164
+ let had404 = false;
165
+ const queryIds = await this.getAboutAccountQueryIds();
166
+ for (const queryId of queryIds) {
167
+ const url = `${TWITTER_API_BASE}/${queryId}/AboutAccountQuery?${params.toString()}`;
168
+ try {
169
+ const response = await this.fetchWithTimeout(url, {
170
+ method: 'GET',
171
+ headers: this.getHeaders(),
172
+ });
173
+ if (!response.ok) {
174
+ const text = await response.text();
175
+ if (response.status === 404) {
176
+ had404 = true;
177
+ lastError = `HTTP ${response.status}`;
178
+ continue;
179
+ }
180
+ lastError = `HTTP ${response.status}: ${text.slice(0, 200)}`;
181
+ continue;
182
+ }
183
+ const data = (await response.json());
184
+ if (data.errors && data.errors.length > 0) {
185
+ lastError = data.errors.map((e) => e.message).join(', ');
186
+ continue;
187
+ }
188
+ const aboutProfile = data.data?.user_result_by_screen_name?.result?.about_profile;
189
+ if (!aboutProfile) {
190
+ lastError = 'Missing about_profile in response';
191
+ continue;
192
+ }
193
+ return {
194
+ success: true,
195
+ aboutProfile: {
196
+ accountBasedIn: aboutProfile.account_based_in,
197
+ source: aboutProfile.source,
198
+ createdCountryAccurate: aboutProfile.created_country_accurate,
199
+ locationAccurate: aboutProfile.location_accurate,
200
+ learnMoreUrl: aboutProfile.learn_more_url,
201
+ },
202
+ had404,
203
+ };
204
+ }
205
+ catch (error) {
206
+ lastError = error instanceof Error ? error.message : String(error);
207
+ }
208
+ }
209
+ return {
210
+ success: false,
211
+ error: lastError ?? 'Unknown error fetching account details',
212
+ had404,
213
+ };
214
+ };
215
+ const { result } = await this.withRefreshedQueryIdsOn404(tryOnce);
216
+ if (result.success) {
217
+ return { success: true, aboutProfile: result.aboutProfile };
218
+ }
219
+ return { success: false, error: result.error };
220
+ }
221
+ }
222
+ return TwitterClientUserLookup;
223
+ }
224
+ //# sourceMappingURL=twitter-client-user-lookup.js.map
@@ -0,0 +1,22 @@
1
+ import type { AbstractConstructor, Mixin, TwitterClientBase } from './twitter-client-base.js';
2
+ import type { SearchResult } from './twitter-client-types.js';
3
+ /** Options for user tweets fetch methods */
4
+ export interface UserTweetsFetchOptions {
5
+ /** Include raw GraphQL response in `_raw` field */
6
+ includeRaw?: boolean;
7
+ }
8
+ /** Options for paginated user tweets fetch */
9
+ export interface UserTweetsPaginationOptions extends UserTweetsFetchOptions {
10
+ /** Maximum number of pages to fetch (default: 1) */
11
+ maxPages?: number;
12
+ /** Starting cursor for pagination (resume from previous fetch) */
13
+ cursor?: string;
14
+ /** Delay in milliseconds between page fetches (default: 1000) */
15
+ pageDelayMs?: number;
16
+ }
17
+ export interface TwitterClientUserTweetsMethods {
18
+ getUserTweets(userId: string, count?: number, options?: UserTweetsFetchOptions): Promise<SearchResult>;
19
+ getUserTweetsPaged(userId: string, limit: number, options?: UserTweetsPaginationOptions): Promise<SearchResult>;
20
+ }
21
+ export declare function withUserTweets<TBase extends AbstractConstructor<TwitterClientBase>>(Base: TBase): Mixin<TBase, TwitterClientUserTweetsMethods>;
22
+ //# sourceMappingURL=twitter-client-user-tweets.d.ts.map
@@ -0,0 +1,154 @@
1
+ import { TWITTER_API_BASE } from './twitter-client-constants.js';
2
+ import { buildUserTweetsFeatures } from './twitter-client-features.js';
3
+ import { extractCursorFromInstructions, parseTweetsFromInstructions } from './twitter-client-utils.js';
4
+ export function withUserTweets(Base) {
5
+ class TwitterClientUserTweets extends Base {
6
+ // biome-ignore lint/complexity/noUselessConstructor lint/suspicious/noExplicitAny: TS mixin constructor requirement.
7
+ constructor(...args) {
8
+ super(...args);
9
+ }
10
+ async getUserTweetsQueryIds() {
11
+ const primary = await this.getQueryId('UserTweets');
12
+ // Fallback query ID observed from web client
13
+ return Array.from(new Set([primary, 'Wms1GvIiHXAPBaCr9KblaA']));
14
+ }
15
+ /**
16
+ * Get tweets from a user's profile timeline (single page).
17
+ */
18
+ async getUserTweets(userId, count = 20, options = {}) {
19
+ return this.getUserTweetsPaged(userId, count, options);
20
+ }
21
+ /**
22
+ * Get tweets from a user's profile timeline with pagination support.
23
+ */
24
+ async getUserTweetsPaged(userId, limit, options = {}) {
25
+ if (!Number.isFinite(limit) || limit <= 0) {
26
+ return { success: false, error: `Invalid limit: ${limit}` };
27
+ }
28
+ const { includeRaw = false, maxPages, pageDelayMs = 1000 } = options;
29
+ const features = buildUserTweetsFeatures();
30
+ const pageSize = 20;
31
+ const seen = new Set();
32
+ const tweets = [];
33
+ let cursor = options.cursor;
34
+ let nextCursor;
35
+ let pagesFetched = 0;
36
+ const hardMaxPages = 10;
37
+ const computedMaxPages = Math.max(1, Math.ceil(limit / pageSize));
38
+ const effectiveMaxPages = Math.min(hardMaxPages, maxPages ?? computedMaxPages);
39
+ const fetchPage = async (pageCount, pageCursor) => {
40
+ let lastError;
41
+ let had404 = false;
42
+ const queryIds = await this.getUserTweetsQueryIds();
43
+ const variables = {
44
+ userId,
45
+ count: pageCount,
46
+ includePromotedContent: false, // Filter out ads
47
+ withQuickPromoteEligibilityTweetFields: true,
48
+ withVoice: true,
49
+ ...(pageCursor ? { cursor: pageCursor } : {}),
50
+ };
51
+ const fieldToggles = {
52
+ withArticlePlainText: false,
53
+ };
54
+ const params = new URLSearchParams({
55
+ variables: JSON.stringify(variables),
56
+ features: JSON.stringify(features),
57
+ fieldToggles: JSON.stringify(fieldToggles),
58
+ });
59
+ for (const queryId of queryIds) {
60
+ const url = `${TWITTER_API_BASE}/${queryId}/UserTweets?${params.toString()}`;
61
+ try {
62
+ const response = await this.fetchWithTimeout(url, {
63
+ method: 'GET',
64
+ headers: this.getHeaders(),
65
+ });
66
+ if (response.status === 404) {
67
+ had404 = true;
68
+ lastError = `HTTP ${response.status}`;
69
+ continue;
70
+ }
71
+ if (!response.ok) {
72
+ const text = await response.text();
73
+ return { success: false, error: `HTTP ${response.status}: ${text.slice(0, 200)}`, had404 };
74
+ }
75
+ const data = (await response.json());
76
+ if (data.errors && data.errors.length > 0) {
77
+ // Check for common errors
78
+ const errorMsg = data.errors.map((e) => e.message).join(', ');
79
+ if (errorMsg.includes('User has been suspended') || errorMsg.includes('User not found')) {
80
+ return { success: false, error: errorMsg, had404 };
81
+ }
82
+ // Some errors are non-fatal if we got data
83
+ if (!data.data?.user?.result?.timeline?.timeline?.instructions) {
84
+ return { success: false, error: errorMsg, had404 };
85
+ }
86
+ }
87
+ const instructions = data.data?.user?.result?.timeline?.timeline?.instructions;
88
+ const pageTweets = parseTweetsFromInstructions(instructions, { quoteDepth: this.quoteDepth, includeRaw });
89
+ const pageCursorValue = extractCursorFromInstructions(instructions);
90
+ return { success: true, tweets: pageTweets, cursor: pageCursorValue, had404 };
91
+ }
92
+ catch (error) {
93
+ lastError = error instanceof Error ? error.message : String(error);
94
+ }
95
+ }
96
+ return { success: false, error: lastError ?? 'Unknown error fetching user tweets', had404 };
97
+ };
98
+ const fetchWithRefresh = async (pageCount, pageCursor) => {
99
+ const firstAttempt = await fetchPage(pageCount, pageCursor);
100
+ if (firstAttempt.success) {
101
+ return firstAttempt;
102
+ }
103
+ if (firstAttempt.had404) {
104
+ await this.refreshQueryIds();
105
+ const secondAttempt = await fetchPage(pageCount, pageCursor);
106
+ if (secondAttempt.success) {
107
+ return secondAttempt;
108
+ }
109
+ return { success: false, error: secondAttempt.error };
110
+ }
111
+ return { success: false, error: firstAttempt.error };
112
+ };
113
+ while (tweets.length < limit) {
114
+ // Add delay between pages (but not before the first page)
115
+ if (pagesFetched > 0 && pageDelayMs > 0) {
116
+ await this.sleep(pageDelayMs);
117
+ }
118
+ const remaining = limit - tweets.length;
119
+ const pageCount = Math.min(pageSize, remaining);
120
+ const page = await fetchWithRefresh(pageCount, cursor);
121
+ if (!page.success) {
122
+ return { success: false, error: page.error };
123
+ }
124
+ pagesFetched += 1;
125
+ let added = 0;
126
+ for (const tweet of page.tweets) {
127
+ if (seen.has(tweet.id)) {
128
+ continue;
129
+ }
130
+ seen.add(tweet.id);
131
+ tweets.push(tweet);
132
+ added += 1;
133
+ if (tweets.length >= limit) {
134
+ break;
135
+ }
136
+ }
137
+ const pageCursor = page.cursor;
138
+ if (!pageCursor || pageCursor === cursor || page.tweets.length === 0 || added === 0) {
139
+ nextCursor = undefined;
140
+ break;
141
+ }
142
+ if (pagesFetched >= effectiveMaxPages) {
143
+ nextCursor = pageCursor;
144
+ break;
145
+ }
146
+ cursor = pageCursor;
147
+ nextCursor = pageCursor;
148
+ }
149
+ return { success: true, tweets, nextCursor };
150
+ }
151
+ }
152
+ return TwitterClientUserTweets;
153
+ }
154
+ //# sourceMappingURL=twitter-client-user-tweets.js.map
@@ -0,0 +1,9 @@
1
+ import type { AbstractConstructor, Mixin, TwitterClientBase } from './twitter-client-base.js';
2
+ import type { CurrentUserResult, FollowingResult } from './twitter-client-types.js';
3
+ export interface TwitterClientUserMethods {
4
+ getCurrentUser(): Promise<CurrentUserResult>;
5
+ getFollowing(userId: string, count?: number, cursor?: string): Promise<FollowingResult>;
6
+ getFollowers(userId: string, count?: number, cursor?: string): Promise<FollowingResult>;
7
+ }
8
+ export declare function withUsers<TBase extends AbstractConstructor<TwitterClientBase>>(Base: TBase): Mixin<TBase, TwitterClientUserMethods>;
9
+ //# sourceMappingURL=twitter-client-users.d.ts.map