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.
Files changed (117) hide show
  1. package/dist/bird/sidecar-entry.js +16 -2
  2. package/dist/bird/sidecar-entry.js.map +1 -1
  3. package/dist/chrome-extension/omni-flow/manifest.json +1 -1
  4. package/node_modules/dp-shared/dist/bird-contracts.d.ts +3 -0
  5. package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
  6. package/node_modules/dp-shared/dist/bird-contracts.js +14 -0
  7. package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
  8. package/package.json +2 -2
  9. package/vendor/bird/LICENSE +21 -0
  10. package/vendor/bird/README.md +58 -0
  11. package/vendor/bird/dist/cli/pagination.d.ts +35 -0
  12. package/vendor/bird/dist/cli/pagination.js +43 -0
  13. package/vendor/bird/dist/cli/program.d.ts +5 -0
  14. package/vendor/bird/dist/cli/program.js +113 -0
  15. package/vendor/bird/dist/cli/shared.d.ts +77 -0
  16. package/vendor/bird/dist/cli/shared.js +327 -0
  17. package/vendor/bird/dist/cli.d.ts +12 -0
  18. package/vendor/bird/dist/cli.js +29 -0
  19. package/vendor/bird/dist/commands/bookmarks.d.ts +4 -0
  20. package/vendor/bird/dist/commands/bookmarks.js +189 -0
  21. package/vendor/bird/dist/commands/check.d.ts +4 -0
  22. package/vendor/bird/dist/commands/check.js +43 -0
  23. package/vendor/bird/dist/commands/follow.d.ts +4 -0
  24. package/vendor/bird/dist/commands/follow.js +91 -0
  25. package/vendor/bird/dist/commands/help.d.ts +4 -0
  26. package/vendor/bird/dist/commands/help.js +19 -0
  27. package/vendor/bird/dist/commands/home.d.ts +4 -0
  28. package/vendor/bird/dist/commands/home.js +43 -0
  29. package/vendor/bird/dist/commands/lists.d.ts +4 -0
  30. package/vendor/bird/dist/commands/lists.js +125 -0
  31. package/vendor/bird/dist/commands/news.d.ts +4 -0
  32. package/vendor/bird/dist/commands/news.js +131 -0
  33. package/vendor/bird/dist/commands/post.d.ts +4 -0
  34. package/vendor/bird/dist/commands/post.js +101 -0
  35. package/vendor/bird/dist/commands/query-ids.d.ts +4 -0
  36. package/vendor/bird/dist/commands/query-ids.js +80 -0
  37. package/vendor/bird/dist/commands/read.d.ts +4 -0
  38. package/vendor/bird/dist/commands/read.js +152 -0
  39. package/vendor/bird/dist/commands/search.d.ts +4 -0
  40. package/vendor/bird/dist/commands/search.js +115 -0
  41. package/vendor/bird/dist/commands/unbookmark.d.ts +4 -0
  42. package/vendor/bird/dist/commands/unbookmark.js +36 -0
  43. package/vendor/bird/dist/commands/user-tweets.d.ts +4 -0
  44. package/vendor/bird/dist/commands/user-tweets.js +109 -0
  45. package/vendor/bird/dist/commands/users.d.ts +4 -0
  46. package/vendor/bird/dist/commands/users.js +295 -0
  47. package/vendor/bird/dist/index.d.ts +2 -0
  48. package/vendor/bird/dist/index.js +2 -0
  49. package/vendor/bird/dist/lib/cli-args.d.ts +7 -0
  50. package/vendor/bird/dist/lib/cli-args.js +25 -0
  51. package/vendor/bird/dist/lib/cookies.d.ts +31 -0
  52. package/vendor/bird/dist/lib/cookies.js +81 -0
  53. package/vendor/bird/dist/lib/extract-bookmark-folder-id.d.ts +2 -0
  54. package/vendor/bird/dist/lib/extract-bookmark-folder-id.js +20 -0
  55. package/vendor/bird/dist/lib/extract-list-id.d.ts +2 -0
  56. package/vendor/bird/dist/lib/extract-list-id.js +19 -0
  57. package/vendor/bird/dist/lib/extract-tweet-id.d.ts +2 -0
  58. package/vendor/bird/dist/lib/extract-tweet-id.js +14 -0
  59. package/vendor/bird/dist/lib/features.json +17 -0
  60. package/vendor/bird/dist/lib/index.d.ts +10 -0
  61. package/vendor/bird/dist/lib/index.js +4 -0
  62. package/vendor/bird/dist/lib/normalize-handle.d.ts +6 -0
  63. package/vendor/bird/dist/lib/normalize-handle.js +31 -0
  64. package/vendor/bird/dist/lib/output.d.ts +29 -0
  65. package/vendor/bird/dist/lib/output.js +88 -0
  66. package/vendor/bird/dist/lib/paginate-cursor.d.ts +27 -0
  67. package/vendor/bird/dist/lib/paginate-cursor.js +37 -0
  68. package/vendor/bird/dist/lib/query-ids.json +20 -0
  69. package/vendor/bird/dist/lib/runtime-features.d.ts +19 -0
  70. package/vendor/bird/dist/lib/runtime-features.js +151 -0
  71. package/vendor/bird/dist/lib/runtime-query-ids.d.ts +33 -0
  72. package/vendor/bird/dist/lib/runtime-query-ids.js +264 -0
  73. package/vendor/bird/dist/lib/thread-filters.d.ts +8 -0
  74. package/vendor/bird/dist/lib/thread-filters.js +124 -0
  75. package/vendor/bird/dist/lib/twitter-client-base.d.ts +38 -0
  76. package/vendor/bird/dist/lib/twitter-client-base.js +129 -0
  77. package/vendor/bird/dist/lib/twitter-client-bookmarks.d.ts +7 -0
  78. package/vendor/bird/dist/lib/twitter-client-bookmarks.js +61 -0
  79. package/vendor/bird/dist/lib/twitter-client-constants.d.ts +43 -0
  80. package/vendor/bird/dist/lib/twitter-client-constants.js +50 -0
  81. package/vendor/bird/dist/lib/twitter-client-engagement.d.ts +16 -0
  82. package/vendor/bird/dist/lib/twitter-client-engagement.js +81 -0
  83. package/vendor/bird/dist/lib/twitter-client-features.d.ts +14 -0
  84. package/vendor/bird/dist/lib/twitter-client-features.js +347 -0
  85. package/vendor/bird/dist/lib/twitter-client-follow.d.ts +8 -0
  86. package/vendor/bird/dist/lib/twitter-client-follow.js +178 -0
  87. package/vendor/bird/dist/lib/twitter-client-home.d.ts +13 -0
  88. package/vendor/bird/dist/lib/twitter-client-home.js +138 -0
  89. package/vendor/bird/dist/lib/twitter-client-lists.d.ts +11 -0
  90. package/vendor/bird/dist/lib/twitter-client-lists.js +321 -0
  91. package/vendor/bird/dist/lib/twitter-client-media.d.ts +11 -0
  92. package/vendor/bird/dist/lib/twitter-client-media.js +136 -0
  93. package/vendor/bird/dist/lib/twitter-client-news.d.ts +47 -0
  94. package/vendor/bird/dist/lib/twitter-client-news.js +283 -0
  95. package/vendor/bird/dist/lib/twitter-client-posting.d.ts +8 -0
  96. package/vendor/bird/dist/lib/twitter-client-posting.js +218 -0
  97. package/vendor/bird/dist/lib/twitter-client-search.d.ts +19 -0
  98. package/vendor/bird/dist/lib/twitter-client-search.js +157 -0
  99. package/vendor/bird/dist/lib/twitter-client-timelines.d.ts +23 -0
  100. package/vendor/bird/dist/lib/twitter-client-timelines.js +471 -0
  101. package/vendor/bird/dist/lib/twitter-client-tweet-detail.d.ts +25 -0
  102. package/vendor/bird/dist/lib/twitter-client-tweet-detail.js +295 -0
  103. package/vendor/bird/dist/lib/twitter-client-types.d.ts +407 -0
  104. package/vendor/bird/dist/lib/twitter-client-types.js +2 -0
  105. package/vendor/bird/dist/lib/twitter-client-user-lookup.d.ts +16 -0
  106. package/vendor/bird/dist/lib/twitter-client-user-lookup.js +224 -0
  107. package/vendor/bird/dist/lib/twitter-client-user-tweets.d.ts +22 -0
  108. package/vendor/bird/dist/lib/twitter-client-user-tweets.js +154 -0
  109. package/vendor/bird/dist/lib/twitter-client-users.d.ts +9 -0
  110. package/vendor/bird/dist/lib/twitter-client-users.js +358 -0
  111. package/vendor/bird/dist/lib/twitter-client-utils.d.ts +173 -0
  112. package/vendor/bird/dist/lib/twitter-client-utils.js +511 -0
  113. package/vendor/bird/dist/lib/twitter-client.d.ts +23 -0
  114. package/vendor/bird/dist/lib/twitter-client.js +21 -0
  115. package/vendor/bird/dist/lib/version.d.ts +6 -0
  116. package/vendor/bird/dist/lib/version.js +174 -0
  117. package/vendor/bird/upstream-package.json +61 -0
@@ -0,0 +1,138 @@
1
+ import { TWITTER_API_BASE } from './twitter-client-constants.js';
2
+ import { buildHomeTimelineFeatures } from './twitter-client-features.js';
3
+ import { extractCursorFromInstructions, parseTweetsFromInstructions } from './twitter-client-utils.js';
4
+ const QUERY_UNSPECIFIED_REGEX = /query:\s*unspecified/i;
5
+ function isQueryIdMismatch(errors) {
6
+ return errors.some((error) => QUERY_UNSPECIFIED_REGEX.test(error.message ?? ''));
7
+ }
8
+ export function withHome(Base) {
9
+ class TwitterClientHome extends Base {
10
+ // biome-ignore lint/complexity/noUselessConstructor lint/suspicious/noExplicitAny: TS mixin constructor requirement.
11
+ constructor(...args) {
12
+ super(...args);
13
+ }
14
+ async getHomeTimelineQueryIds() {
15
+ const primary = await this.getQueryId('HomeTimeline');
16
+ return Array.from(new Set([primary, 'edseUwk9sP5Phz__9TIRnA']));
17
+ }
18
+ async getHomeLatestTimelineQueryIds() {
19
+ const primary = await this.getQueryId('HomeLatestTimeline');
20
+ return Array.from(new Set([primary, 'iOEZpOdfekFsxSlPQCQtPg']));
21
+ }
22
+ /**
23
+ * Get the authenticated user's "For You" home timeline
24
+ */
25
+ async getHomeTimeline(count = 20, options = {}) {
26
+ return this.fetchHomeTimeline('HomeTimeline', count, options);
27
+ }
28
+ /**
29
+ * Get the authenticated user's "Following" (latest/chronological) home timeline
30
+ */
31
+ async getHomeLatestTimeline(count = 20, options = {}) {
32
+ return this.fetchHomeTimeline('HomeLatestTimeline', count, options);
33
+ }
34
+ async fetchHomeTimeline(operation, count, options) {
35
+ const { includeRaw = false } = options;
36
+ const features = buildHomeTimelineFeatures();
37
+ const pageSize = 20;
38
+ const seen = new Set();
39
+ const tweets = [];
40
+ let cursor;
41
+ const fetchPage = async (pageCount, pageCursor) => {
42
+ let lastError;
43
+ let had404 = false;
44
+ const queryIds = operation === 'HomeTimeline'
45
+ ? await this.getHomeTimelineQueryIds()
46
+ : await this.getHomeLatestTimelineQueryIds();
47
+ for (const queryId of queryIds) {
48
+ const variables = {
49
+ count: pageCount,
50
+ includePromotedContent: true,
51
+ latestControlAvailable: true,
52
+ requestContext: 'launch',
53
+ withCommunity: true,
54
+ ...(pageCursor ? { cursor: pageCursor } : {}),
55
+ };
56
+ const params = new URLSearchParams({
57
+ variables: JSON.stringify(variables),
58
+ features: JSON.stringify(features),
59
+ });
60
+ const url = `${TWITTER_API_BASE}/${queryId}/${operation}?${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
+ const errorMessage = data.errors.map((e) => e.message).join(', ');
78
+ return {
79
+ success: false,
80
+ error: errorMessage,
81
+ had404: had404 || isQueryIdMismatch(data.errors),
82
+ };
83
+ }
84
+ const instructions = data.data?.home?.home_timeline_urt?.instructions;
85
+ const pageTweets = parseTweetsFromInstructions(instructions, { quoteDepth: this.quoteDepth, includeRaw });
86
+ const nextCursor = extractCursorFromInstructions(instructions);
87
+ return { success: true, tweets: pageTweets, cursor: nextCursor, had404 };
88
+ }
89
+ catch (error) {
90
+ lastError = error instanceof Error ? error.message : String(error);
91
+ }
92
+ }
93
+ return { success: false, error: lastError ?? 'Unknown error fetching home timeline', had404 };
94
+ };
95
+ const fetchWithRefresh = async (pageCount, pageCursor) => {
96
+ const firstAttempt = await fetchPage(pageCount, pageCursor);
97
+ if (firstAttempt.success) {
98
+ return firstAttempt;
99
+ }
100
+ if (firstAttempt.had404) {
101
+ await this.refreshQueryIds();
102
+ const secondAttempt = await fetchPage(pageCount, pageCursor);
103
+ if (secondAttempt.success) {
104
+ return secondAttempt;
105
+ }
106
+ return { success: false, error: secondAttempt.error };
107
+ }
108
+ return { success: false, error: firstAttempt.error };
109
+ };
110
+ while (tweets.length < count) {
111
+ const pageCount = Math.min(pageSize, count - tweets.length);
112
+ const page = await fetchWithRefresh(pageCount, cursor);
113
+ if (!page.success) {
114
+ return { success: false, error: page.error };
115
+ }
116
+ let added = 0;
117
+ for (const tweet of page.tweets) {
118
+ if (seen.has(tweet.id)) {
119
+ continue;
120
+ }
121
+ seen.add(tweet.id);
122
+ tweets.push(tweet);
123
+ added += 1;
124
+ if (tweets.length >= count) {
125
+ break;
126
+ }
127
+ }
128
+ if (!page.cursor || page.cursor === cursor || page.tweets.length === 0 || added === 0) {
129
+ break;
130
+ }
131
+ cursor = page.cursor;
132
+ }
133
+ return { success: true, tweets };
134
+ }
135
+ }
136
+ return TwitterClientHome;
137
+ }
138
+ //# sourceMappingURL=twitter-client-home.js.map
@@ -0,0 +1,11 @@
1
+ import type { AbstractConstructor, Mixin, TwitterClientBase } from './twitter-client-base.js';
2
+ import type { TimelineFetchOptions, TimelinePaginationOptions } from './twitter-client-timelines.js';
3
+ import type { ListsResult, SearchResult } from './twitter-client-types.js';
4
+ export interface TwitterClientListMethods {
5
+ getOwnedLists(count?: number): Promise<ListsResult>;
6
+ getListMemberships(count?: number): Promise<ListsResult>;
7
+ getListTimeline(listId: string, count?: number, options?: TimelineFetchOptions): Promise<SearchResult>;
8
+ getAllListTimeline(listId: string, options?: TimelinePaginationOptions): Promise<SearchResult>;
9
+ }
10
+ export declare function withLists<TBase extends AbstractConstructor<TwitterClientBase>>(Base: TBase): Mixin<TBase, TwitterClientListMethods>;
11
+ //# sourceMappingURL=twitter-client-lists.d.ts.map
@@ -0,0 +1,321 @@
1
+ // ABOUTME: Mixin for Twitter Lists GraphQL operations.
2
+ // ABOUTME: Provides methods to fetch user's owned lists, memberships, and list timelines.
3
+ import { TWITTER_API_BASE } from './twitter-client-constants.js';
4
+ import { buildListsFeatures } from './twitter-client-features.js';
5
+ import { extractCursorFromInstructions, parseTweetsFromInstructions } from './twitter-client-utils.js';
6
+ function parseList(listResult) {
7
+ if (!listResult.id_str || !listResult.name) {
8
+ return null;
9
+ }
10
+ const owner = listResult.user_results?.result;
11
+ return {
12
+ id: listResult.id_str,
13
+ name: listResult.name,
14
+ description: listResult.description,
15
+ memberCount: listResult.member_count,
16
+ subscriberCount: listResult.subscriber_count,
17
+ isPrivate: listResult.mode?.toLowerCase() === 'private',
18
+ createdAt: listResult.created_at,
19
+ owner: owner
20
+ ? {
21
+ id: owner.rest_id ?? '',
22
+ username: owner.legacy?.screen_name ?? '',
23
+ name: owner.legacy?.name ?? '',
24
+ }
25
+ : undefined,
26
+ };
27
+ }
28
+ function parseListsFromInstructions(instructions) {
29
+ const lists = [];
30
+ if (!instructions) {
31
+ return lists;
32
+ }
33
+ for (const instruction of instructions) {
34
+ if (!instruction.entries) {
35
+ continue;
36
+ }
37
+ for (const entry of instruction.entries) {
38
+ const listResult = entry.content?.itemContent?.list;
39
+ if (listResult) {
40
+ const parsed = parseList(listResult);
41
+ if (parsed) {
42
+ lists.push(parsed);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ return lists;
48
+ }
49
+ export function withLists(Base) {
50
+ class TwitterClientLists extends Base {
51
+ // biome-ignore lint/complexity/noUselessConstructor lint/suspicious/noExplicitAny: TS mixin constructor requirement.
52
+ constructor(...args) {
53
+ super(...args);
54
+ }
55
+ async getListOwnershipsQueryIds() {
56
+ const primary = await this.getQueryId('ListOwnerships');
57
+ return Array.from(new Set([primary, 'wQcOSjSQ8NtgxIwvYl1lMg']));
58
+ }
59
+ async getListMembershipsQueryIds() {
60
+ const primary = await this.getQueryId('ListMemberships');
61
+ return Array.from(new Set([primary, 'BlEXXdARdSeL_0KyKHHvvg']));
62
+ }
63
+ async getListTimelineQueryIds() {
64
+ const primary = await this.getQueryId('ListLatestTweetsTimeline');
65
+ return Array.from(new Set([primary, '2TemLyqrMpTeAmysdbnVqw']));
66
+ }
67
+ /**
68
+ * Get lists owned by the authenticated user
69
+ */
70
+ async getOwnedLists(count = 100) {
71
+ const userResult = await this.getCurrentUser();
72
+ if (!userResult.success || !userResult.user) {
73
+ return { success: false, error: userResult.error ?? 'Could not determine current user' };
74
+ }
75
+ const variables = {
76
+ userId: userResult.user.id,
77
+ count,
78
+ isListMembershipShown: true,
79
+ isListMemberTargetUserId: userResult.user.id,
80
+ };
81
+ const features = buildListsFeatures();
82
+ const params = new URLSearchParams({
83
+ variables: JSON.stringify(variables),
84
+ features: JSON.stringify(features),
85
+ });
86
+ const tryOnce = async () => {
87
+ let lastError;
88
+ let had404 = false;
89
+ const queryIds = await this.getListOwnershipsQueryIds();
90
+ for (const queryId of queryIds) {
91
+ const url = `${TWITTER_API_BASE}/${queryId}/ListOwnerships?${params.toString()}`;
92
+ try {
93
+ const response = await this.fetchWithTimeout(url, {
94
+ method: 'GET',
95
+ headers: this.getHeaders(),
96
+ });
97
+ if (response.status === 404) {
98
+ had404 = true;
99
+ lastError = `HTTP ${response.status}`;
100
+ continue;
101
+ }
102
+ if (!response.ok) {
103
+ const text = await response.text();
104
+ return { success: false, error: `HTTP ${response.status}: ${text.slice(0, 200)}`, had404 };
105
+ }
106
+ const data = (await response.json());
107
+ if (data.errors && data.errors.length > 0) {
108
+ return { success: false, error: data.errors.map((e) => e.message).join(', '), had404 };
109
+ }
110
+ const instructions = data.data?.user?.result?.timeline?.timeline?.instructions;
111
+ const lists = parseListsFromInstructions(instructions);
112
+ return { success: true, lists, had404 };
113
+ }
114
+ catch (error) {
115
+ lastError = error instanceof Error ? error.message : String(error);
116
+ }
117
+ }
118
+ return { success: false, error: lastError ?? 'Unknown error fetching owned lists', had404 };
119
+ };
120
+ const firstAttempt = await tryOnce();
121
+ if (firstAttempt.success) {
122
+ return { success: true, lists: firstAttempt.lists };
123
+ }
124
+ if (firstAttempt.had404) {
125
+ await this.refreshQueryIds();
126
+ const secondAttempt = await tryOnce();
127
+ if (secondAttempt.success) {
128
+ return { success: true, lists: secondAttempt.lists };
129
+ }
130
+ return { success: false, error: secondAttempt.error };
131
+ }
132
+ return { success: false, error: firstAttempt.error };
133
+ }
134
+ /**
135
+ * Get lists the authenticated user is a member of
136
+ */
137
+ async getListMemberships(count = 100) {
138
+ const userResult = await this.getCurrentUser();
139
+ if (!userResult.success || !userResult.user) {
140
+ return { success: false, error: userResult.error ?? 'Could not determine current user' };
141
+ }
142
+ const variables = {
143
+ userId: userResult.user.id,
144
+ count,
145
+ isListMembershipShown: true,
146
+ isListMemberTargetUserId: userResult.user.id,
147
+ };
148
+ const features = buildListsFeatures();
149
+ const params = new URLSearchParams({
150
+ variables: JSON.stringify(variables),
151
+ features: JSON.stringify(features),
152
+ });
153
+ const tryOnce = async () => {
154
+ let lastError;
155
+ let had404 = false;
156
+ const queryIds = await this.getListMembershipsQueryIds();
157
+ for (const queryId of queryIds) {
158
+ const url = `${TWITTER_API_BASE}/${queryId}/ListMemberships?${params.toString()}`;
159
+ try {
160
+ const response = await this.fetchWithTimeout(url, {
161
+ method: 'GET',
162
+ headers: this.getHeaders(),
163
+ });
164
+ if (response.status === 404) {
165
+ had404 = true;
166
+ lastError = `HTTP ${response.status}`;
167
+ continue;
168
+ }
169
+ if (!response.ok) {
170
+ const text = await response.text();
171
+ return { success: false, error: `HTTP ${response.status}: ${text.slice(0, 200)}`, had404 };
172
+ }
173
+ const data = (await response.json());
174
+ if (data.errors && data.errors.length > 0) {
175
+ return { success: false, error: data.errors.map((e) => e.message).join(', '), had404 };
176
+ }
177
+ const instructions = data.data?.user?.result?.timeline?.timeline?.instructions;
178
+ const lists = parseListsFromInstructions(instructions);
179
+ return { success: true, lists, had404 };
180
+ }
181
+ catch (error) {
182
+ lastError = error instanceof Error ? error.message : String(error);
183
+ }
184
+ }
185
+ return { success: false, error: lastError ?? 'Unknown error fetching list memberships', had404 };
186
+ };
187
+ const firstAttempt = await tryOnce();
188
+ if (firstAttempt.success) {
189
+ return { success: true, lists: firstAttempt.lists };
190
+ }
191
+ if (firstAttempt.had404) {
192
+ await this.refreshQueryIds();
193
+ const secondAttempt = await tryOnce();
194
+ if (secondAttempt.success) {
195
+ return { success: true, lists: secondAttempt.lists };
196
+ }
197
+ return { success: false, error: secondAttempt.error };
198
+ }
199
+ return { success: false, error: firstAttempt.error };
200
+ }
201
+ /**
202
+ * Get tweets from a list timeline
203
+ */
204
+ async getListTimeline(listId, count = 20, options = {}) {
205
+ return this.getListTimelinePaged(listId, count, options);
206
+ }
207
+ /**
208
+ * Get all tweets from a list timeline (paginated)
209
+ */
210
+ async getAllListTimeline(listId, options) {
211
+ return this.getListTimelinePaged(listId, Number.POSITIVE_INFINITY, options);
212
+ }
213
+ /**
214
+ * Internal paginated list timeline fetcher
215
+ */
216
+ async getListTimelinePaged(listId, limit, options = {}) {
217
+ const features = buildListsFeatures();
218
+ const pageSize = 20;
219
+ const seen = new Set();
220
+ const tweets = [];
221
+ let cursor = options.cursor;
222
+ let nextCursor;
223
+ let pagesFetched = 0;
224
+ const { includeRaw = false, maxPages } = options;
225
+ const fetchPage = async (pageCount, pageCursor) => {
226
+ let lastError;
227
+ let had404 = false;
228
+ const queryIds = await this.getListTimelineQueryIds();
229
+ const variables = {
230
+ listId,
231
+ count: pageCount,
232
+ ...(pageCursor ? { cursor: pageCursor } : {}),
233
+ };
234
+ const params = new URLSearchParams({
235
+ variables: JSON.stringify(variables),
236
+ features: JSON.stringify(features),
237
+ });
238
+ for (const queryId of queryIds) {
239
+ const url = `${TWITTER_API_BASE}/${queryId}/ListLatestTweetsTimeline?${params.toString()}`;
240
+ try {
241
+ const response = await this.fetchWithTimeout(url, {
242
+ method: 'GET',
243
+ headers: this.getHeaders(),
244
+ });
245
+ if (response.status === 404) {
246
+ had404 = true;
247
+ lastError = `HTTP ${response.status}`;
248
+ continue;
249
+ }
250
+ if (!response.ok) {
251
+ const text = await response.text();
252
+ return { success: false, error: `HTTP ${response.status}: ${text.slice(0, 200)}`, had404 };
253
+ }
254
+ const data = (await response.json());
255
+ if (data.errors && data.errors.length > 0) {
256
+ return { success: false, error: data.errors.map((e) => e.message).join(', '), had404 };
257
+ }
258
+ const instructions = data.data?.list?.tweets_timeline?.timeline?.instructions;
259
+ const pageTweets = parseTweetsFromInstructions(instructions, { quoteDepth: this.quoteDepth, includeRaw });
260
+ const nextCursor = extractCursorFromInstructions(instructions);
261
+ return { success: true, tweets: pageTweets, cursor: nextCursor, had404 };
262
+ }
263
+ catch (error) {
264
+ lastError = error instanceof Error ? error.message : String(error);
265
+ }
266
+ }
267
+ return { success: false, error: lastError ?? 'Unknown error fetching list timeline', had404 };
268
+ };
269
+ const fetchWithRefresh = async (pageCount, pageCursor) => {
270
+ const firstAttempt = await fetchPage(pageCount, pageCursor);
271
+ if (firstAttempt.success) {
272
+ return firstAttempt;
273
+ }
274
+ if (firstAttempt.had404) {
275
+ await this.refreshQueryIds();
276
+ const secondAttempt = await fetchPage(pageCount, pageCursor);
277
+ if (secondAttempt.success) {
278
+ return secondAttempt;
279
+ }
280
+ return { success: false, error: secondAttempt.error };
281
+ }
282
+ return { success: false, error: firstAttempt.error };
283
+ };
284
+ const unlimited = limit === Number.POSITIVE_INFINITY;
285
+ while (unlimited || tweets.length < limit) {
286
+ const pageCount = unlimited ? pageSize : Math.min(pageSize, limit - tweets.length);
287
+ const page = await fetchWithRefresh(pageCount, cursor);
288
+ if (!page.success) {
289
+ return { success: false, error: page.error };
290
+ }
291
+ pagesFetched += 1;
292
+ let added = 0;
293
+ for (const tweet of page.tweets) {
294
+ if (seen.has(tweet.id)) {
295
+ continue;
296
+ }
297
+ seen.add(tweet.id);
298
+ tweets.push(tweet);
299
+ added += 1;
300
+ if (!unlimited && tweets.length >= limit) {
301
+ break;
302
+ }
303
+ }
304
+ const pageCursor = page.cursor;
305
+ if (!pageCursor || pageCursor === cursor || page.tweets.length === 0 || added === 0) {
306
+ nextCursor = undefined;
307
+ break;
308
+ }
309
+ if (maxPages && pagesFetched >= maxPages) {
310
+ nextCursor = pageCursor;
311
+ break;
312
+ }
313
+ cursor = pageCursor;
314
+ nextCursor = pageCursor;
315
+ }
316
+ return { success: true, tweets, nextCursor };
317
+ }
318
+ }
319
+ return TwitterClientLists;
320
+ }
321
+ //# sourceMappingURL=twitter-client-lists.js.map
@@ -0,0 +1,11 @@
1
+ import type { AbstractConstructor, Mixin, TwitterClientBase } from './twitter-client-base.js';
2
+ import type { UploadMediaResult } from './twitter-client-types.js';
3
+ export interface TwitterClientMediaMethods {
4
+ uploadMedia(input: {
5
+ data: Uint8Array;
6
+ mimeType: string;
7
+ alt?: string;
8
+ }): Promise<UploadMediaResult>;
9
+ }
10
+ export declare function withMedia<TBase extends AbstractConstructor<TwitterClientBase>>(Base: TBase): Mixin<TBase, TwitterClientMediaMethods>;
11
+ //# sourceMappingURL=twitter-client-media.d.ts.map
@@ -0,0 +1,136 @@
1
+ import { TWITTER_MEDIA_METADATA_URL, TWITTER_UPLOAD_URL } from './twitter-client-constants.js';
2
+ export function withMedia(Base) {
3
+ class TwitterClientMedia extends Base {
4
+ // biome-ignore lint/complexity/noUselessConstructor lint/suspicious/noExplicitAny: TS mixin constructor requirement.
5
+ constructor(...args) {
6
+ super(...args);
7
+ }
8
+ mediaCategoryForMime(mimeType) {
9
+ if (mimeType.startsWith('image/')) {
10
+ if (mimeType === 'image/gif') {
11
+ return 'tweet_gif';
12
+ }
13
+ return 'tweet_image';
14
+ }
15
+ if (mimeType.startsWith('video/')) {
16
+ return 'tweet_video';
17
+ }
18
+ return null;
19
+ }
20
+ async uploadMedia(input) {
21
+ const category = this.mediaCategoryForMime(input.mimeType);
22
+ if (!category) {
23
+ return { success: false, error: `Unsupported media type: ${input.mimeType}` };
24
+ }
25
+ try {
26
+ const initParams = new URLSearchParams({
27
+ command: 'INIT',
28
+ total_bytes: String(input.data.byteLength),
29
+ media_type: input.mimeType,
30
+ media_category: category,
31
+ });
32
+ const initResp = await this.fetchWithTimeout(TWITTER_UPLOAD_URL, {
33
+ method: 'POST',
34
+ headers: this.getUploadHeaders(),
35
+ body: initParams,
36
+ });
37
+ if (!initResp.ok) {
38
+ const text = await initResp.text();
39
+ return { success: false, error: `HTTP ${initResp.status}: ${text.slice(0, 200)}` };
40
+ }
41
+ const initBody = (await initResp.json());
42
+ const mediaId = typeof initBody.media_id_string === 'string'
43
+ ? initBody.media_id_string
44
+ : initBody.media_id !== undefined
45
+ ? String(initBody.media_id)
46
+ : undefined;
47
+ if (!mediaId) {
48
+ return { success: false, error: 'Media upload INIT did not return media_id' };
49
+ }
50
+ const chunkSize = 5 * 1024 * 1024;
51
+ let segmentIndex = 0;
52
+ for (let offset = 0; offset < input.data.byteLength; offset += chunkSize) {
53
+ const chunk = input.data.slice(offset, Math.min(input.data.byteLength, offset + chunkSize));
54
+ const form = new FormData();
55
+ form.set('command', 'APPEND');
56
+ form.set('media_id', mediaId);
57
+ form.set('segment_index', String(segmentIndex));
58
+ form.set('media', new Blob([chunk], { type: input.mimeType }), 'media');
59
+ const appendResp = await this.fetchWithTimeout(TWITTER_UPLOAD_URL, {
60
+ method: 'POST',
61
+ headers: this.getUploadHeaders(),
62
+ body: form,
63
+ });
64
+ if (!appendResp.ok) {
65
+ const text = await appendResp.text();
66
+ return { success: false, error: `HTTP ${appendResp.status}: ${text.slice(0, 200)}` };
67
+ }
68
+ segmentIndex += 1;
69
+ }
70
+ const finalizeParams = new URLSearchParams({ command: 'FINALIZE', media_id: mediaId });
71
+ const finalizeResp = await this.fetchWithTimeout(TWITTER_UPLOAD_URL, {
72
+ method: 'POST',
73
+ headers: this.getUploadHeaders(),
74
+ body: finalizeParams,
75
+ });
76
+ if (!finalizeResp.ok) {
77
+ const text = await finalizeResp.text();
78
+ return { success: false, error: `HTTP ${finalizeResp.status}: ${text.slice(0, 200)}` };
79
+ }
80
+ const finalizeBody = (await finalizeResp.json());
81
+ const info = finalizeBody.processing_info;
82
+ if (info?.state && info.state !== 'succeeded') {
83
+ let attempts = 0;
84
+ while (attempts < 20) {
85
+ if (info.state === 'failed') {
86
+ const msg = info.error?.message || info.error?.name || 'Media processing failed';
87
+ return { success: false, error: msg };
88
+ }
89
+ const delaySecs = Number.isFinite(info.check_after_secs) ? Math.max(1, info.check_after_secs) : 2;
90
+ await this.sleep(delaySecs * 1000);
91
+ const statusUrl = `${TWITTER_UPLOAD_URL}?${new URLSearchParams({
92
+ command: 'STATUS',
93
+ media_id: mediaId,
94
+ }).toString()}`;
95
+ const statusResp = await this.fetchWithTimeout(statusUrl, {
96
+ method: 'GET',
97
+ headers: this.getUploadHeaders(),
98
+ });
99
+ if (!statusResp.ok) {
100
+ const text = await statusResp.text();
101
+ return { success: false, error: `HTTP ${statusResp.status}: ${text.slice(0, 200)}` };
102
+ }
103
+ const statusBody = (await statusResp.json());
104
+ if (!statusBody.processing_info) {
105
+ break;
106
+ }
107
+ info.state = statusBody.processing_info.state;
108
+ info.check_after_secs = statusBody.processing_info.check_after_secs;
109
+ info.error = statusBody.processing_info.error;
110
+ if (info.state === 'succeeded') {
111
+ break;
112
+ }
113
+ attempts += 1;
114
+ }
115
+ }
116
+ if (input.alt && input.mimeType.startsWith('image/')) {
117
+ const metaResp = await this.fetchWithTimeout(TWITTER_MEDIA_METADATA_URL, {
118
+ method: 'POST',
119
+ headers: this.getJsonHeaders(),
120
+ body: JSON.stringify({ media_id: mediaId, alt_text: { text: input.alt } }),
121
+ });
122
+ if (!metaResp.ok) {
123
+ const text = await metaResp.text();
124
+ return { success: false, error: `HTTP ${metaResp.status}: ${text.slice(0, 200)}` };
125
+ }
126
+ }
127
+ return { success: true, mediaId };
128
+ }
129
+ catch (error) {
130
+ return { success: false, error: error instanceof Error ? error.message : String(error) };
131
+ }
132
+ }
133
+ }
134
+ return TwitterClientMedia;
135
+ }
136
+ //# sourceMappingURL=twitter-client-media.js.map
@@ -0,0 +1,47 @@
1
+ import type { AbstractConstructor, Mixin, TwitterClientBase } from './twitter-client-base.js';
2
+ import type { TweetData } from './twitter-client-types.js';
3
+ declare const TIMELINE_IDS: {
4
+ readonly forYou: "VGltZWxpbmU6DAC2CwABAAAAB2Zvcl95b3UAAA==";
5
+ readonly trending: "VGltZWxpbmU6DAC2CwABAAAACHRyZW5kaW5nAAA=";
6
+ readonly news: "VGltZWxpbmU6DAC2CwABAAAABG5ld3MAAA==";
7
+ readonly sports: "VGltZWxpbmU6DAC2CwABAAAABnNwb3J0cwAA";
8
+ readonly entertainment: "VGltZWxpbmU6DAC2CwABAAAADWVudGVydGFpbm1lbnQAAA==";
9
+ };
10
+ export type ExploreTab = keyof typeof TIMELINE_IDS;
11
+ /** Options for news fetch methods */
12
+ export interface NewsFetchOptions {
13
+ /** Include raw GraphQL response in `_raw` field */
14
+ includeRaw?: boolean;
15
+ /** Also fetch related tweets for each news item */
16
+ withTweets?: boolean;
17
+ /** Number of tweets to fetch per news item (default: 5) */
18
+ tweetsPerItem?: number;
19
+ /** Filter to show only AI-curated news items */
20
+ aiOnly?: boolean;
21
+ /** Fetch from specific tabs only (default: all tabs) */
22
+ tabs?: ExploreTab[];
23
+ }
24
+ export interface NewsItem {
25
+ id: string;
26
+ headline: string;
27
+ category?: string;
28
+ timeAgo?: string;
29
+ postCount?: number;
30
+ description?: string;
31
+ url?: string;
32
+ tweets?: TweetData[];
33
+ _raw?: any;
34
+ }
35
+ export type NewsResult = {
36
+ success: true;
37
+ items: NewsItem[];
38
+ } | {
39
+ success: false;
40
+ error: string;
41
+ };
42
+ export interface TwitterClientNewsMethods {
43
+ getNews(count?: number, options?: NewsFetchOptions): Promise<NewsResult>;
44
+ }
45
+ export declare function withNews<TBase extends AbstractConstructor<TwitterClientBase>>(Base: TBase): Mixin<TBase, TwitterClientNewsMethods>;
46
+ export {};
47
+ //# sourceMappingURL=twitter-client-news.d.ts.map