fix lists queries and authenticated list reading
This commit is contained in:
@@ -1,5 +1,16 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.10.1 — 2026-07-26
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Add `getLists()` for the authenticated account's “Your Lists” timeline.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Refresh Lists query IDs, variables, and feature flags.
|
||||||
|
- Keep usable list and tweet data when optional GraphQL fields return partial errors.
|
||||||
|
|
||||||
## 0.10.0 — 2026-07-14
|
## 0.10.0 — 2026-07-14
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ Fields:
|
|||||||
- `bird likes [-n count] [--all] [--max-pages n] [--cursor string] [--json] [--json-full]` — list your liked tweets; `--max-pages` requires `--all` or `--cursor`.
|
- `bird likes [-n count] [--all] [--max-pages n] [--cursor string] [--json] [--json-full]` — list your liked tweets; `--max-pages` requires `--all` or `--cursor`.
|
||||||
- `bird news [-n count] [--ai-only] [--with-tweets] [--tweets-per-item n] [--for-you] [--news-only] [--sports] [--entertainment] [--trending-only] [--json]` — fetch news and trending topics from X's Explore tabs.
|
- `bird news [-n count] [--ai-only] [--with-tweets] [--tweets-per-item n] [--for-you] [--news-only] [--sports] [--entertainment] [--trending-only] [--json]` — fetch news and trending topics from X's Explore tabs.
|
||||||
- `bird trending` — alias for `news` command.
|
- `bird trending` — alias for `news` command.
|
||||||
- `bird lists [--member-of] [-n count] [--json]` — list your lists (owned or memberships).
|
- `bird lists [--member-of] [-n count] [--json]` — list the authenticated account's “Your Lists”, or memberships with `--member-of`.
|
||||||
- `bird list-timeline <list-id-or-url> [-n count] [--all] [--max-pages n] [--cursor string] [--json]` — get tweets from a list timeline; `--max-pages` implies `--all`.
|
- `bird list-timeline <list-id-or-url> [-n count] [--all] [--max-pages n] [--cursor string] [--json]` — get tweets from a list timeline; `--max-pages` implies `--all`.
|
||||||
- `bird following [--user <userId>] [-n count] [--cursor string] [--all] [--max-pages n] [--json]` — list users that you (or another user) follow; `--max-pages` requires `--all`.
|
- `bird following [--user <userId>] [-n count] [--cursor string] [--all] [--max-pages n] [--json]` — list users that you (or another user) follow; `--max-pages` requires `--all`.
|
||||||
- `bird followers [--user <userId>] [-n count] [--cursor string] [--all] [--max-pages n] [--json]` — list users that follow you (or another user); `--max-pages` requires `--all`.
|
- `bird followers [--user <userId>] [-n count] [--cursor string] [--all] [--max-pages n] [--json]` — list users that follow you (or another user); `--max-pages` requires `--all`.
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@yuta/bird",
|
"name": "@yuta/bird",
|
||||||
"version": "0.10.0",
|
"version": "0.10.1",
|
||||||
"description": "CLI tool for tweeting and replying via Twitter/X GraphQL API",
|
"description": "CLI tool for tweeting and replying via Twitter/X GraphQL API",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ const TARGET_OPERATIONS = [
|
|||||||
'GenericTimelineById',
|
'GenericTimelineById',
|
||||||
'TrendHistory',
|
'TrendHistory',
|
||||||
'AboutAccountQuery',
|
'AboutAccountQuery',
|
||||||
|
'ListsManagementPageTimeline',
|
||||||
|
'ListOwnerships',
|
||||||
|
'ListMemberships',
|
||||||
|
'ListLatestTweetsTimeline',
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
type OperationName = (typeof TARGET_OPERATIONS)[number];
|
type OperationName = (typeof TARGET_OPERATIONS)[number];
|
||||||
@@ -36,6 +40,7 @@ type OperationName = (typeof TARGET_OPERATIONS)[number];
|
|||||||
const DISCOVERY_PAGES = [
|
const DISCOVERY_PAGES = [
|
||||||
'https://x.com/?lang=en',
|
'https://x.com/?lang=en',
|
||||||
'https://x.com/explore',
|
'https://x.com/explore',
|
||||||
|
'https://x.com/i/lists',
|
||||||
'https://x.com/notifications',
|
'https://x.com/notifications',
|
||||||
'https://x.com/settings/profile',
|
'https://x.com/settings/profile',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ export function registerListsCommand(program: Command, ctx: CliContext): void {
|
|||||||
|
|
||||||
const client = new TwitterClient({ relayBaseUrl, profileName, timeoutMs });
|
const client = new TwitterClient({ relayBaseUrl, profileName, timeoutMs });
|
||||||
|
|
||||||
const result = cmdOpts.memberOf ? await client.getListMemberships(count) : await client.getOwnedLists(count);
|
const result = cmdOpts.memberOf ? await client.getListMemberships(count) : await client.getLists(count);
|
||||||
|
|
||||||
if (result.success && result.lists) {
|
if (result.success && result.lists) {
|
||||||
if (cmdOpts.json) {
|
if (cmdOpts.json) {
|
||||||
console.log(JSON.stringify(result.lists, null, 2));
|
console.log(JSON.stringify(result.lists, null, 2));
|
||||||
} else {
|
} else {
|
||||||
const emptyMessage = cmdOpts.memberOf ? 'You are not a member of any lists.' : 'You do not own any lists.';
|
const emptyMessage = cmdOpts.memberOf ? 'You are not a member of any lists.' : 'No lists found.';
|
||||||
if (result.lists.length === 0) {
|
if (result.lists.length === 0) {
|
||||||
console.log(emptyMessage);
|
console.log(emptyMessage);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
refreshFeatureOverridesCache,
|
refreshFeatureOverridesCache,
|
||||||
} from '../lib/runtime-features.js';
|
} from '../lib/runtime-features.js';
|
||||||
import { runtimeQueryIds } from '../lib/runtime-query-ids.js';
|
import { runtimeQueryIds } from '../lib/runtime-query-ids.js';
|
||||||
|
import { TARGET_QUERY_ID_OPERATIONS } from '../lib/twitter-client-constants.js';
|
||||||
|
|
||||||
function countFeatureOverrides(overrides: FeatureOverrides): number {
|
function countFeatureOverrides(overrides: FeatureOverrides): number {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
@@ -27,22 +28,9 @@ export function registerQueryIdsCommand(program: Command, ctx: CliContext): void
|
|||||||
.option('--json', 'Output as JSON')
|
.option('--json', 'Output as JSON')
|
||||||
.option('--fresh', 'Force refresh (downloads X client bundles)', false)
|
.option('--fresh', 'Force refresh (downloads X client bundles)', false)
|
||||||
.action(async (cmdOpts: { json?: boolean; fresh?: boolean }) => {
|
.action(async (cmdOpts: { json?: boolean; fresh?: boolean }) => {
|
||||||
const operations = [
|
|
||||||
'CreateTweet',
|
|
||||||
'CreateRetweet',
|
|
||||||
'FavoriteTweet',
|
|
||||||
'TweetDetail',
|
|
||||||
'SearchTimeline',
|
|
||||||
'UserArticlesTweets',
|
|
||||||
'Bookmarks',
|
|
||||||
'Following',
|
|
||||||
'Followers',
|
|
||||||
'Likes',
|
|
||||||
];
|
|
||||||
|
|
||||||
if (cmdOpts.fresh) {
|
if (cmdOpts.fresh) {
|
||||||
console.error(`${ctx.p('info')}Refreshing GraphQL query IDs…`);
|
console.error(`${ctx.p('info')}Refreshing GraphQL query IDs…`);
|
||||||
await runtimeQueryIds.refresh(operations, { force: true });
|
await runtimeQueryIds.refresh(TARGET_QUERY_ID_OPERATIONS, { force: true });
|
||||||
console.error(`${ctx.p('info')}Refreshing feature overrides…`);
|
console.error(`${ctx.p('info')}Refreshing feature overrides…`);
|
||||||
await refreshFeatureOverridesCache();
|
await refreshFeatureOverridesCache();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-12
@@ -1,17 +1,7 @@
|
|||||||
{
|
{
|
||||||
"global": {
|
"global": {
|
||||||
"responsive_web_grok_annotations_enabled": false,
|
"responsive_web_grok_annotations_enabled": false,
|
||||||
"post_ctas_fetch_enabled": true,
|
"post_ctas_fetch_enabled": true
|
||||||
"responsive_web_graphql_exclude_directive_enabled": true
|
|
||||||
},
|
},
|
||||||
"sets": {
|
"sets": {}
|
||||||
"lists": {
|
|
||||||
"blue_business_profile_image_shape_enabled": true,
|
|
||||||
"tweetypie_unmention_optimization_enabled": true,
|
|
||||||
"responsive_web_text_conversations_enabled": false,
|
|
||||||
"interactive_text_enabled": true,
|
|
||||||
"vibe_api_enabled": true,
|
|
||||||
"responsive_web_twitter_blue_verified_badge_is_enabled": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,5 +16,9 @@
|
|||||||
"ExplorePage": "kheAINB_4pzRDqkzG3K-ng",
|
"ExplorePage": "kheAINB_4pzRDqkzG3K-ng",
|
||||||
"GenericTimelineById": "uGSr7alSjR9v6QJAIaqSKQ",
|
"GenericTimelineById": "uGSr7alSjR9v6QJAIaqSKQ",
|
||||||
"TrendHistory": "Sj4T-jSB9pr0Mxtsc1UKZQ",
|
"TrendHistory": "Sj4T-jSB9pr0Mxtsc1UKZQ",
|
||||||
"AboutAccountQuery": "zs_jFPFT78rBpXv9Z3U2YQ"
|
"AboutAccountQuery": "zs_jFPFT78rBpXv9Z3U2YQ",
|
||||||
|
"ListsManagementPageTimeline": "I96vj5eyw1D9g_NA0wWj3Q",
|
||||||
|
"ListOwnerships": "N_9HejNT9Amo1tDF7Gb_TQ",
|
||||||
|
"ListMemberships": "EPnwxyczkTMNNqPjlCBP9Q",
|
||||||
|
"ListLatestTweetsTimeline": "K77PSxWq_St4HLusAV9nVg"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const DEFAULT_TTL_MS: number = 24 * 60 * 60 * 1000;
|
|||||||
const DISCOVERY_PAGES: string[] = [
|
const DISCOVERY_PAGES: string[] = [
|
||||||
'https://x.com/?lang=en',
|
'https://x.com/?lang=en',
|
||||||
'https://x.com/explore',
|
'https://x.com/explore',
|
||||||
|
'https://x.com/i/lists',
|
||||||
'https://x.com/notifications',
|
'https://x.com/notifications',
|
||||||
'https://x.com/settings/profile',
|
'https://x.com/settings/profile',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -28,10 +28,10 @@ export const FALLBACK_QUERY_IDS = {
|
|||||||
Followers: 'kuFUYP9eV1FPoEy4N-pi7w',
|
Followers: 'kuFUYP9eV1FPoEy4N-pi7w',
|
||||||
Likes: 'JR2gceKucIKcVNB_9JkhsA',
|
Likes: 'JR2gceKucIKcVNB_9JkhsA',
|
||||||
BookmarkFolderTimeline: 'KJIQpsvxrTfRIlbaRIySHQ',
|
BookmarkFolderTimeline: 'KJIQpsvxrTfRIlbaRIySHQ',
|
||||||
ListOwnerships: 'wQcOSjSQ8NtgxIwvYl1lMg',
|
ListsManagementPageTimeline: 'I96vj5eyw1D9g_NA0wWj3Q',
|
||||||
ListMemberships: 'BlEXXdARdSeL_0KyKHHvvg',
|
ListOwnerships: 'N_9HejNT9Amo1tDF7Gb_TQ',
|
||||||
ListLatestTweetsTimeline: '2TemLyqrMpTeAmysdbnVqw',
|
ListMemberships: 'EPnwxyczkTMNNqPjlCBP9Q',
|
||||||
ListByRestId: 'wXzyA5vM_aVkBL9G8Vp3kw',
|
ListLatestTweetsTimeline: 'K77PSxWq_St4HLusAV9nVg',
|
||||||
HomeTimeline: 'edseUwk9sP5Phz__9TIRnA',
|
HomeTimeline: 'edseUwk9sP5Phz__9TIRnA',
|
||||||
HomeLatestTimeline: 'iOEZpOdfekFsxSlPQCQtPg',
|
HomeLatestTimeline: 'iOEZpOdfekFsxSlPQCQtPg',
|
||||||
ExploreSidebar: 'lpSN4M6qpimkF4nRFPE3nQ',
|
ExploreSidebar: 'lpSN4M6qpimkF4nRFPE3nQ',
|
||||||
|
|||||||
@@ -180,50 +180,47 @@ export function buildLikesFeatures(): Record<string, boolean> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function buildListsFeatures(): Record<string, boolean> {
|
export function buildListsFeatures(): Record<string, boolean> {
|
||||||
return applyFeatureOverrides('lists', {
|
return {
|
||||||
rweb_video_screen_enabled: true,
|
rweb_video_screen_enabled: false,
|
||||||
|
rweb_cashtags_enabled: true,
|
||||||
profile_label_improvements_pcf_label_in_post_enabled: true,
|
profile_label_improvements_pcf_label_in_post_enabled: true,
|
||||||
responsive_web_profile_redirect_enabled: true,
|
responsive_web_profile_redirect_enabled: false,
|
||||||
rweb_tipjar_consumption_enabled: true,
|
rweb_tipjar_consumption_enabled: false,
|
||||||
verified_phone_label_enabled: false,
|
verified_phone_label_enabled: false,
|
||||||
creator_subscriptions_tweet_preview_api_enabled: true,
|
creator_subscriptions_tweet_preview_api_enabled: true,
|
||||||
responsive_web_graphql_timeline_navigation_enabled: true,
|
responsive_web_graphql_timeline_navigation_enabled: true,
|
||||||
responsive_web_graphql_exclude_directive_enabled: true,
|
|
||||||
responsive_web_graphql_skip_user_profile_image_extensions_enabled: false,
|
responsive_web_graphql_skip_user_profile_image_extensions_enabled: false,
|
||||||
premium_content_api_read_enabled: false,
|
premium_content_api_read_enabled: false,
|
||||||
communities_web_enable_tweet_community_results_fetch: true,
|
communities_web_enable_tweet_community_results_fetch: true,
|
||||||
c9s_tweet_anatomy_moderator_badge_enabled: true,
|
c9s_tweet_anatomy_moderator_badge_enabled: true,
|
||||||
responsive_web_grok_analyze_button_fetch_trends_enabled: false,
|
responsive_web_grok_analyze_button_fetch_trends_enabled: false,
|
||||||
responsive_web_grok_analyze_post_followups_enabled: false,
|
responsive_web_grok_analyze_post_followups_enabled: true,
|
||||||
responsive_web_grok_annotations_enabled: false,
|
rweb_cashtags_composer_attachment_enabled: true,
|
||||||
responsive_web_jetfuel_frame: true,
|
responsive_web_jetfuel_frame: true,
|
||||||
post_ctas_fetch_enabled: true,
|
|
||||||
responsive_web_grok_share_attachment_enabled: true,
|
responsive_web_grok_share_attachment_enabled: true,
|
||||||
|
responsive_web_grok_annotations_enabled: true,
|
||||||
articles_preview_enabled: true,
|
articles_preview_enabled: true,
|
||||||
responsive_web_edit_tweet_api_enabled: true,
|
responsive_web_edit_tweet_api_enabled: true,
|
||||||
|
rweb_conversational_replies_downvote_enabled: false,
|
||||||
graphql_is_translatable_rweb_tweet_is_translatable_enabled: true,
|
graphql_is_translatable_rweb_tweet_is_translatable_enabled: true,
|
||||||
view_counts_everywhere_api_enabled: true,
|
view_counts_everywhere_api_enabled: true,
|
||||||
longform_notetweets_consumption_enabled: true,
|
longform_notetweets_consumption_enabled: true,
|
||||||
responsive_web_twitter_article_tweet_consumption_enabled: true,
|
responsive_web_twitter_article_tweet_consumption_enabled: true,
|
||||||
tweet_awards_web_tipping_enabled: false,
|
content_disclosure_indicator_enabled: true,
|
||||||
responsive_web_grok_show_grok_translated_post: false,
|
content_disclosure_ai_generated_indicator_enabled: true,
|
||||||
|
responsive_web_grok_show_grok_translated_post: true,
|
||||||
responsive_web_grok_analysis_button_from_backend: true,
|
responsive_web_grok_analysis_button_from_backend: true,
|
||||||
creator_subscriptions_quote_tweet_preview_enabled: false,
|
post_ctas_fetch_enabled: true,
|
||||||
freedom_of_speech_not_reach_fetch_enabled: true,
|
freedom_of_speech_not_reach_fetch_enabled: true,
|
||||||
standardized_nudges_misinfo: true,
|
standardized_nudges_misinfo: true,
|
||||||
tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled: true,
|
tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled: true,
|
||||||
longform_notetweets_rich_text_read_enabled: true,
|
longform_notetweets_rich_text_read_enabled: true,
|
||||||
longform_notetweets_inline_media_enabled: true,
|
longform_notetweets_inline_media_enabled: false,
|
||||||
responsive_web_grok_image_annotation_enabled: true,
|
responsive_web_grok_image_annotation_enabled: true,
|
||||||
responsive_web_grok_imagine_annotation_enabled: true,
|
responsive_web_grok_imagine_annotation_enabled: true,
|
||||||
responsive_web_grok_community_note_auto_translation_is_enabled: false,
|
responsive_web_grok_community_note_auto_translation_is_enabled: true,
|
||||||
responsive_web_enhance_cards_enabled: false,
|
responsive_web_enhance_cards_enabled: false,
|
||||||
blue_business_profile_image_shape_enabled: false,
|
};
|
||||||
responsive_web_text_conversations_enabled: false,
|
|
||||||
tweetypie_unmention_optimization_enabled: true,
|
|
||||||
vibe_api_enabled: false,
|
|
||||||
interactive_text_enabled: false,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildHomeTimelineFeatures(): Record<string, boolean> {
|
export function buildHomeTimelineFeatures(): Record<string, boolean> {
|
||||||
|
|||||||
+197
-223
@@ -9,6 +9,7 @@ import type { GraphqlTweetResult, ListsResult, SearchResult, TweetData, TwitterL
|
|||||||
import { extractCursorFromInstructions, parseTweetsFromInstructions } from './twitter-client-utils.js';
|
import { extractCursorFromInstructions, parseTweetsFromInstructions } from './twitter-client-utils.js';
|
||||||
|
|
||||||
export interface TwitterClientListMethods {
|
export interface TwitterClientListMethods {
|
||||||
|
getLists(count?: number): Promise<ListsResult>;
|
||||||
getOwnedLists(count?: number): Promise<ListsResult>;
|
getOwnedLists(count?: number): Promise<ListsResult>;
|
||||||
getListMemberships(count?: number): Promise<ListsResult>;
|
getListMemberships(count?: number): Promise<ListsResult>;
|
||||||
getListTimeline(listId: string, count?: number, options?: TimelineFetchOptions): Promise<SearchResult>;
|
getListTimeline(listId: string, count?: number, options?: TimelineFetchOptions): Promise<SearchResult>;
|
||||||
@@ -22,7 +23,7 @@ interface GraphqlListResult {
|
|||||||
member_count?: number;
|
member_count?: number;
|
||||||
subscriber_count?: number;
|
subscriber_count?: number;
|
||||||
mode?: string;
|
mode?: string;
|
||||||
created_at?: string;
|
created_at?: string | number;
|
||||||
user_results?: {
|
user_results?: {
|
||||||
result?: {
|
result?: {
|
||||||
rest_id?: string;
|
rest_id?: string;
|
||||||
@@ -30,16 +31,73 @@ interface GraphqlListResult {
|
|||||||
screen_name?: string;
|
screen_name?: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
};
|
};
|
||||||
|
core?: {
|
||||||
|
screen_name?: string;
|
||||||
|
name?: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface GraphqlListItem {
|
||||||
|
itemContent?: {
|
||||||
|
list?: GraphqlListResult;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GraphqlListInstruction {
|
||||||
|
entries?: Array<{
|
||||||
|
content?: GraphqlListItem & {
|
||||||
|
clientEventInfo?: {
|
||||||
|
component?: string;
|
||||||
|
};
|
||||||
|
items?: Array<{
|
||||||
|
item?: GraphqlListItem;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GraphqlListsResponse {
|
||||||
|
data?: {
|
||||||
|
user?: {
|
||||||
|
result?: {
|
||||||
|
__typename?: string;
|
||||||
|
timeline?: {
|
||||||
|
timeline?: {
|
||||||
|
instructions?: GraphqlListInstruction[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
viewer?: {
|
||||||
|
list_management_timeline?: {
|
||||||
|
timeline?: {
|
||||||
|
instructions?: GraphqlListInstruction[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
errors?: Array<{ message: string }>;
|
||||||
|
}
|
||||||
|
|
||||||
function parseList(listResult: GraphqlListResult): TwitterList | null {
|
function parseList(listResult: GraphqlListResult): TwitterList | null {
|
||||||
if (!listResult.id_str || !listResult.name) {
|
if (!listResult.id_str || !listResult.name) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const owner = listResult.user_results?.result;
|
const owner = listResult.user_results?.result;
|
||||||
|
const ownerProfile = owner?.core ?? owner?.legacy;
|
||||||
|
const createdAtDate =
|
||||||
|
typeof listResult.created_at === 'number' && Number.isFinite(listResult.created_at)
|
||||||
|
? new Date(listResult.created_at)
|
||||||
|
: null;
|
||||||
|
const createdAt =
|
||||||
|
createdAtDate && !Number.isNaN(createdAtDate.getTime())
|
||||||
|
? createdAtDate.toISOString()
|
||||||
|
: typeof listResult.created_at === 'string'
|
||||||
|
? listResult.created_at
|
||||||
|
: undefined;
|
||||||
return {
|
return {
|
||||||
id: listResult.id_str,
|
id: listResult.id_str,
|
||||||
name: listResult.name,
|
name: listResult.name,
|
||||||
@@ -47,51 +105,49 @@ function parseList(listResult: GraphqlListResult): TwitterList | null {
|
|||||||
memberCount: listResult.member_count,
|
memberCount: listResult.member_count,
|
||||||
subscriberCount: listResult.subscriber_count,
|
subscriberCount: listResult.subscriber_count,
|
||||||
isPrivate: listResult.mode?.toLowerCase() === 'private',
|
isPrivate: listResult.mode?.toLowerCase() === 'private',
|
||||||
createdAt: listResult.created_at,
|
createdAt,
|
||||||
owner: owner
|
owner: owner
|
||||||
? {
|
? {
|
||||||
id: owner.rest_id ?? '',
|
id: owner.rest_id ?? '',
|
||||||
username: owner.legacy?.screen_name ?? '',
|
username: ownerProfile?.screen_name ?? '',
|
||||||
name: owner.legacy?.name ?? '',
|
name: ownerProfile?.name ?? '',
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseListsFromInstructions(
|
function parseListsFromInstructions(
|
||||||
instructions:
|
instructions: GraphqlListInstruction[] | undefined,
|
||||||
| Array<{
|
component?: string,
|
||||||
entries?: Array<{
|
|
||||||
content?: {
|
|
||||||
itemContent?: {
|
|
||||||
list?: GraphqlListResult;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}>;
|
|
||||||
}>
|
|
||||||
| undefined,
|
|
||||||
): TwitterList[] {
|
): TwitterList[] {
|
||||||
const lists: TwitterList[] = [];
|
const lists = new Map<string, TwitterList>();
|
||||||
if (!instructions) {
|
if (!instructions) {
|
||||||
return lists;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const instruction of instructions) {
|
const addList = (listResult: GraphqlListResult | undefined) => {
|
||||||
if (!instruction.entries) {
|
if (!listResult) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
for (const entry of instruction.entries) {
|
const parsed = parseList(listResult);
|
||||||
const listResult = entry.content?.itemContent?.list;
|
if (parsed) {
|
||||||
if (listResult) {
|
lists.set(parsed.id, parsed);
|
||||||
const parsed = parseList(listResult);
|
}
|
||||||
if (parsed) {
|
};
|
||||||
lists.push(parsed);
|
|
||||||
}
|
for (const instruction of instructions) {
|
||||||
|
for (const entry of instruction.entries ?? []) {
|
||||||
|
if (component && entry.content?.clientEventInfo?.component !== component) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
addList(entry.content?.itemContent?.list);
|
||||||
|
for (const item of entry.content?.items ?? []) {
|
||||||
|
addList(item.item?.itemContent?.list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lists;
|
return Array.from(lists.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function withLists<TBase extends AbstractConstructor<TwitterClientBase>>(
|
export function withLists<TBase extends AbstractConstructor<TwitterClientBase>>(
|
||||||
@@ -103,19 +159,108 @@ export function withLists<TBase extends AbstractConstructor<TwitterClientBase>>(
|
|||||||
super(...args);
|
super(...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getListsManagementQueryIds(): Promise<string[]> {
|
||||||
|
return [await this.getQueryId('ListsManagementPageTimeline')];
|
||||||
|
}
|
||||||
|
|
||||||
private async getListOwnershipsQueryIds(): Promise<string[]> {
|
private async getListOwnershipsQueryIds(): Promise<string[]> {
|
||||||
const primary = await this.getQueryId('ListOwnerships');
|
return [await this.getQueryId('ListOwnerships')];
|
||||||
return Array.from(new Set([primary, 'wQcOSjSQ8NtgxIwvYl1lMg']));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getListMembershipsQueryIds(): Promise<string[]> {
|
private async getListMembershipsQueryIds(): Promise<string[]> {
|
||||||
const primary = await this.getQueryId('ListMemberships');
|
return [await this.getQueryId('ListMemberships')];
|
||||||
return Array.from(new Set([primary, 'BlEXXdARdSeL_0KyKHHvvg']));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getListTimelineQueryIds(): Promise<string[]> {
|
private async getListTimelineQueryIds(): Promise<string[]> {
|
||||||
const primary = await this.getQueryId('ListLatestTweetsTimeline');
|
return [await this.getQueryId('ListLatestTweetsTimeline')];
|
||||||
return Array.from(new Set([primary, '2TemLyqrMpTeAmysdbnVqw']));
|
}
|
||||||
|
|
||||||
|
private async fetchListsOperation(
|
||||||
|
operationName: 'ListsManagementPageTimeline' | 'ListOwnerships' | 'ListMemberships',
|
||||||
|
variables: Record<string, unknown>,
|
||||||
|
getQueryIds: () => Promise<string[]>,
|
||||||
|
selectInstructions: (data: GraphqlListsResponse) => GraphqlListInstruction[] | undefined,
|
||||||
|
component?: string,
|
||||||
|
): Promise<ListsResult> {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
variables: JSON.stringify(variables),
|
||||||
|
features: JSON.stringify(buildListsFeatures()),
|
||||||
|
});
|
||||||
|
|
||||||
|
const tryOnce = async () => {
|
||||||
|
let lastError: string | undefined;
|
||||||
|
let had404 = false;
|
||||||
|
|
||||||
|
for (const queryId of await getQueryIds()) {
|
||||||
|
const url = `${TWITTER_API_BASE}/${queryId}/${operationName}?${params.toString()}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await this.fetchWithTimeout(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: this.getHeaders(),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.status === 404) {
|
||||||
|
had404 = true;
|
||||||
|
lastError = `HTTP ${response.status}`;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const text = await response.text();
|
||||||
|
return { success: false as const, error: `HTTP ${response.status}: ${text.slice(0, 200)}`, had404 };
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = (await response.json()) as GraphqlListsResponse;
|
||||||
|
const instructions = selectInstructions(data);
|
||||||
|
if (instructions) {
|
||||||
|
return { success: true as const, lists: parseListsFromInstructions(instructions, component), had404 };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.data?.user?.result?.__typename === 'UserUnavailable') {
|
||||||
|
return { success: false as const, error: 'User unavailable', had404 };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.errors?.length) {
|
||||||
|
return { success: false as const, error: data.errors.map((error) => error.message).join(', '), had404 };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: false as const, error: `Missing ${operationName} timeline`, had404 };
|
||||||
|
} catch (error) {
|
||||||
|
lastError = error instanceof Error ? error.message : String(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: false as const, error: lastError ?? `Unknown error fetching ${operationName}`, had404 };
|
||||||
|
};
|
||||||
|
|
||||||
|
const firstAttempt = await tryOnce();
|
||||||
|
if (firstAttempt.success) {
|
||||||
|
return { success: true, lists: firstAttempt.lists };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!firstAttempt.had404) {
|
||||||
|
return { success: false, error: firstAttempt.error };
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.refreshQueryIds();
|
||||||
|
const secondAttempt = await tryOnce();
|
||||||
|
return secondAttempt.success
|
||||||
|
? { success: true, lists: secondAttempt.lists }
|
||||||
|
: { success: false, error: secondAttempt.error };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the lists shown on the authenticated user's Lists page.
|
||||||
|
*/
|
||||||
|
async getLists(count = 100): Promise<ListsResult> {
|
||||||
|
return this.fetchListsOperation(
|
||||||
|
'ListsManagementPageTimeline',
|
||||||
|
{ count },
|
||||||
|
() => this.getListsManagementQueryIds(),
|
||||||
|
(data) => data.data?.viewer?.list_management_timeline?.timeline?.instructions,
|
||||||
|
'suggest_owned_subscribed_list',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,99 +272,16 @@ export function withLists<TBase extends AbstractConstructor<TwitterClientBase>>(
|
|||||||
return { success: false, error: userResult.error ?? 'Could not determine current user' };
|
return { success: false, error: userResult.error ?? 'Could not determine current user' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const variables = {
|
return this.fetchListsOperation(
|
||||||
userId: userResult.user.id,
|
'ListOwnerships',
|
||||||
count,
|
{
|
||||||
isListMembershipShown: true,
|
userId: userResult.user.id,
|
||||||
isListMemberTargetUserId: userResult.user.id,
|
isListMemberTargetUserId: userResult.user.id,
|
||||||
};
|
count,
|
||||||
|
},
|
||||||
const features = buildListsFeatures();
|
() => this.getListOwnershipsQueryIds(),
|
||||||
|
(data) => data.data?.user?.result?.timeline?.timeline?.instructions,
|
||||||
const params = new URLSearchParams({
|
);
|
||||||
variables: JSON.stringify(variables),
|
|
||||||
features: JSON.stringify(features),
|
|
||||||
});
|
|
||||||
|
|
||||||
const tryOnce = async () => {
|
|
||||||
let lastError: string | undefined;
|
|
||||||
let had404 = false;
|
|
||||||
const queryIds = await this.getListOwnershipsQueryIds();
|
|
||||||
|
|
||||||
for (const queryId of queryIds) {
|
|
||||||
const url = `${TWITTER_API_BASE}/${queryId}/ListOwnerships?${params.toString()}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.fetchWithTimeout(url, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: this.getHeaders(),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.status === 404) {
|
|
||||||
had404 = true;
|
|
||||||
lastError = `HTTP ${response.status}`;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const text = await response.text();
|
|
||||||
return { success: false as const, error: `HTTP ${response.status}: ${text.slice(0, 200)}`, had404 };
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = (await response.json()) as {
|
|
||||||
data?: {
|
|
||||||
user?: {
|
|
||||||
result?: {
|
|
||||||
timeline?: {
|
|
||||||
timeline?: {
|
|
||||||
instructions?: Array<{
|
|
||||||
entries?: Array<{
|
|
||||||
content?: {
|
|
||||||
itemContent?: {
|
|
||||||
list?: GraphqlListResult;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}>;
|
|
||||||
}>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
errors?: Array<{ message: string }>;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (data.errors && data.errors.length > 0) {
|
|
||||||
return { success: false as const, error: data.errors.map((e) => e.message).join(', '), had404 };
|
|
||||||
}
|
|
||||||
|
|
||||||
const instructions = data.data?.user?.result?.timeline?.timeline?.instructions;
|
|
||||||
const lists = parseListsFromInstructions(instructions);
|
|
||||||
|
|
||||||
return { success: true as const, lists, had404 };
|
|
||||||
} catch (error) {
|
|
||||||
lastError = error instanceof Error ? error.message : String(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { success: false as const, error: lastError ?? 'Unknown error fetching owned lists', had404 };
|
|
||||||
};
|
|
||||||
|
|
||||||
const firstAttempt = await tryOnce();
|
|
||||||
if (firstAttempt.success) {
|
|
||||||
return { success: true, lists: firstAttempt.lists };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstAttempt.had404) {
|
|
||||||
await this.refreshQueryIds();
|
|
||||||
const secondAttempt = await tryOnce();
|
|
||||||
if (secondAttempt.success) {
|
|
||||||
return { success: true, lists: secondAttempt.lists };
|
|
||||||
}
|
|
||||||
return { success: false, error: secondAttempt.error };
|
|
||||||
}
|
|
||||||
|
|
||||||
return { success: false, error: firstAttempt.error };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -231,99 +293,12 @@ export function withLists<TBase extends AbstractConstructor<TwitterClientBase>>(
|
|||||||
return { success: false, error: userResult.error ?? 'Could not determine current user' };
|
return { success: false, error: userResult.error ?? 'Could not determine current user' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const variables = {
|
return this.fetchListsOperation(
|
||||||
userId: userResult.user.id,
|
'ListMemberships',
|
||||||
count,
|
{ userId: userResult.user.id, count },
|
||||||
isListMembershipShown: true,
|
() => this.getListMembershipsQueryIds(),
|
||||||
isListMemberTargetUserId: userResult.user.id,
|
(data) => data.data?.user?.result?.timeline?.timeline?.instructions,
|
||||||
};
|
);
|
||||||
|
|
||||||
const features = buildListsFeatures();
|
|
||||||
|
|
||||||
const params = new URLSearchParams({
|
|
||||||
variables: JSON.stringify(variables),
|
|
||||||
features: JSON.stringify(features),
|
|
||||||
});
|
|
||||||
|
|
||||||
const tryOnce = async () => {
|
|
||||||
let lastError: string | undefined;
|
|
||||||
let had404 = false;
|
|
||||||
const queryIds = await this.getListMembershipsQueryIds();
|
|
||||||
|
|
||||||
for (const queryId of queryIds) {
|
|
||||||
const url = `${TWITTER_API_BASE}/${queryId}/ListMemberships?${params.toString()}`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await this.fetchWithTimeout(url, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: this.getHeaders(),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.status === 404) {
|
|
||||||
had404 = true;
|
|
||||||
lastError = `HTTP ${response.status}`;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
const text = await response.text();
|
|
||||||
return { success: false as const, error: `HTTP ${response.status}: ${text.slice(0, 200)}`, had404 };
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = (await response.json()) as {
|
|
||||||
data?: {
|
|
||||||
user?: {
|
|
||||||
result?: {
|
|
||||||
timeline?: {
|
|
||||||
timeline?: {
|
|
||||||
instructions?: Array<{
|
|
||||||
entries?: Array<{
|
|
||||||
content?: {
|
|
||||||
itemContent?: {
|
|
||||||
list?: GraphqlListResult;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}>;
|
|
||||||
}>;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
errors?: Array<{ message: string }>;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (data.errors && data.errors.length > 0) {
|
|
||||||
return { success: false as const, error: data.errors.map((e) => e.message).join(', '), had404 };
|
|
||||||
}
|
|
||||||
|
|
||||||
const instructions = data.data?.user?.result?.timeline?.timeline?.instructions;
|
|
||||||
const lists = parseListsFromInstructions(instructions);
|
|
||||||
|
|
||||||
return { success: true as const, lists, had404 };
|
|
||||||
} catch (error) {
|
|
||||||
lastError = error instanceof Error ? error.message : String(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { success: false as const, error: lastError ?? 'Unknown error fetching list memberships', had404 };
|
|
||||||
};
|
|
||||||
|
|
||||||
const firstAttempt = await tryOnce();
|
|
||||||
if (firstAttempt.success) {
|
|
||||||
return { success: true, lists: firstAttempt.lists };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstAttempt.had404) {
|
|
||||||
await this.refreshQueryIds();
|
|
||||||
const secondAttempt = await tryOnce();
|
|
||||||
if (secondAttempt.success) {
|
|
||||||
return { success: true, lists: secondAttempt.lists };
|
|
||||||
}
|
|
||||||
return { success: false, error: secondAttempt.error };
|
|
||||||
}
|
|
||||||
|
|
||||||
return { success: false, error: firstAttempt.error };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -416,11 +391,10 @@ export function withLists<TBase extends AbstractConstructor<TwitterClientBase>>(
|
|||||||
errors?: Array<{ message: string }>;
|
errors?: Array<{ message: string }>;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (data.errors && data.errors.length > 0) {
|
const instructions = data.data?.list?.tweets_timeline?.timeline?.instructions;
|
||||||
|
if (!instructions && data.errors?.length) {
|
||||||
return { success: false as const, error: data.errors.map((e) => e.message).join(', '), had404 };
|
return { success: false as const, error: data.errors.map((e) => e.message).join(', '), had404 };
|
||||||
}
|
}
|
||||||
|
|
||||||
const instructions = data.data?.list?.tweets_timeline?.timeline?.instructions;
|
|
||||||
const pageTweets = parseTweetsFromInstructions(instructions, { quoteDepth: this.quoteDepth, includeRaw });
|
const pageTweets = parseTweetsFromInstructions(instructions, { quoteDepth: this.quoteDepth, includeRaw });
|
||||||
const nextCursor = extractCursorFromInstructions(instructions);
|
const nextCursor = extractCursorFromInstructions(instructions);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { Command } from 'commander';
|
||||||
|
import { describe, expect, it, vi } from 'vitest';
|
||||||
|
import type { CliContext } from '../src/cli/shared.js';
|
||||||
|
import { registerListsCommand } from '../src/commands/lists.js';
|
||||||
|
import { TwitterClient } from '../src/lib/twitter-client.js';
|
||||||
|
|
||||||
|
describe('lists command', () => {
|
||||||
|
it('uses the authenticated Lists page by default', async () => {
|
||||||
|
const program = new Command();
|
||||||
|
const ctx = {
|
||||||
|
resolveTimeoutFromOptions: () => undefined,
|
||||||
|
resolveRelayBaseUrlFromOptions: () => 'https://relay.example',
|
||||||
|
resolveProfileNameFromOptions: () => undefined,
|
||||||
|
p: () => '',
|
||||||
|
colors: { muted: (value: string) => value, accent: (value: string) => value },
|
||||||
|
getOutput: () => 'plain',
|
||||||
|
} as unknown as CliContext;
|
||||||
|
const listsSpy = vi.spyOn(TwitterClient.prototype, 'getLists').mockResolvedValue({
|
||||||
|
success: true,
|
||||||
|
lists: [],
|
||||||
|
});
|
||||||
|
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
||||||
|
|
||||||
|
try {
|
||||||
|
registerListsCommand(program, ctx);
|
||||||
|
await program.parseAsync(['node', 'bird', 'lists', '--count', '25']);
|
||||||
|
|
||||||
|
expect(listsSpy).toHaveBeenCalledWith(25);
|
||||||
|
expect(logSpy).toHaveBeenCalledWith('No lists found.');
|
||||||
|
} finally {
|
||||||
|
listsSpy.mockRestore();
|
||||||
|
logSpy.mockRestore();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -29,9 +29,6 @@ describe('runtime-features', () => {
|
|||||||
likes: {
|
likes: {
|
||||||
likes_only: true,
|
likes_only: true,
|
||||||
},
|
},
|
||||||
lists: {
|
|
||||||
responsive_web_text_conversations_enabled: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -44,9 +41,6 @@ describe('runtime-features', () => {
|
|||||||
const likes = buildLikesFeatures();
|
const likes = buildLikesFeatures();
|
||||||
expect(likes.global_flag).toBe(true);
|
expect(likes.global_flag).toBe(true);
|
||||||
expect(likes.likes_only).toBe(true);
|
expect(likes.likes_only).toBe(true);
|
||||||
|
|
||||||
const lists = buildListsFeatures();
|
|
||||||
expect(lists.responsive_web_text_conversations_enabled).toBe(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('refresh merges defaults with existing cache', async () => {
|
it('refresh merges defaults with existing cache', async () => {
|
||||||
@@ -119,11 +113,28 @@ describe('runtime-features', () => {
|
|||||||
|
|
||||||
it('includes required lists API feature flags', () => {
|
it('includes required lists API feature flags', () => {
|
||||||
const features = buildListsFeatures();
|
const features = buildListsFeatures();
|
||||||
expect(features.responsive_web_graphql_exclude_directive_enabled).toBe(true);
|
expect(features.responsive_web_graphql_exclude_directive_enabled).toBeUndefined();
|
||||||
expect(features.blue_business_profile_image_shape_enabled).toBe(true);
|
expect(features.responsive_web_grok_annotations_enabled).toBe(true);
|
||||||
expect(features.responsive_web_text_conversations_enabled).toBe(false);
|
expect(features.rweb_cashtags_enabled).toBe(true);
|
||||||
expect(features.tweetypie_unmention_optimization_enabled).toBe(true);
|
expect(features.responsive_web_grok_show_grok_translated_post).toBe(true);
|
||||||
expect(features.vibe_api_enabled).toBe(true);
|
expect(features.longform_notetweets_inline_media_enabled).toBe(false);
|
||||||
expect(features.interactive_text_enabled).toBe(true);
|
});
|
||||||
|
|
||||||
|
it('keeps catalog-locked list features independent from runtime overrides', () => {
|
||||||
|
process.env.BIRD_FEATURES_JSON = JSON.stringify({
|
||||||
|
global: {
|
||||||
|
responsive_web_grok_annotations_enabled: false,
|
||||||
|
},
|
||||||
|
sets: {
|
||||||
|
lists: {
|
||||||
|
rweb_cashtags_enabled: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
clearFeatureOverridesCache();
|
||||||
|
|
||||||
|
const features = buildListsFeatures();
|
||||||
|
expect(features.responsive_web_grok_annotations_enabled).toBe(true);
|
||||||
|
expect(features.rweb_cashtags_enabled).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export type TwitterClientPrivate = TwitterClient & {
|
|||||||
error?: string;
|
error?: string;
|
||||||
}>;
|
}>;
|
||||||
getLikesQueryIds: () => Promise<string[]>;
|
getLikesQueryIds: () => Promise<string[]>;
|
||||||
|
getListsManagementQueryIds: () => Promise<string[]>;
|
||||||
getListTimelineQueryIds: () => Promise<string[]>;
|
getListTimelineQueryIds: () => Promise<string[]>;
|
||||||
getListOwnershipsQueryIds: () => Promise<string[]>;
|
getListOwnershipsQueryIds: () => Promise<string[]>;
|
||||||
getListMembershipsQueryIds: () => Promise<string[]>;
|
getListMembershipsQueryIds: () => Promise<string[]>;
|
||||||
|
|||||||
@@ -0,0 +1,171 @@
|
|||||||
|
// ABOUTME: Tests for the authenticated user's Lists management timeline.
|
||||||
|
// ABOUTME: Covers nested list items, deduplication, and partial GraphQL errors.
|
||||||
|
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
import { TwitterClient } from '../src/lib/twitter-client.js';
|
||||||
|
import { type TwitterClientPrivate, testRelayBaseUrl } from './twitter-client-fixtures.js';
|
||||||
|
|
||||||
|
const originalFetch = global.fetch;
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
global.fetch = originalFetch;
|
||||||
|
vi.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('TwitterClient lists management', () => {
|
||||||
|
let mockFetch: ReturnType<typeof vi.fn>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockFetch = vi.fn();
|
||||||
|
global.fetch = mockFetch as unknown as typeof fetch;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gets and deduplicates the lists shown on the authenticated Lists page', async () => {
|
||||||
|
const list = {
|
||||||
|
id_str: '1234567890',
|
||||||
|
name: 'My List',
|
||||||
|
description: 'A useful list',
|
||||||
|
member_count: 10,
|
||||||
|
mode: 'Private',
|
||||||
|
created_at: 1_704_067_200_000,
|
||||||
|
user_results: {
|
||||||
|
result: {
|
||||||
|
rest_id: '12345',
|
||||||
|
core: { screen_name: 'testuser', name: 'Test User' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
mockFetch.mockResolvedValueOnce({
|
||||||
|
ok: true,
|
||||||
|
status: 200,
|
||||||
|
json: async () => ({
|
||||||
|
data: {
|
||||||
|
viewer: {
|
||||||
|
list_management_timeline: {
|
||||||
|
timeline: {
|
||||||
|
instructions: [
|
||||||
|
{
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
content: {
|
||||||
|
clientEventInfo: { component: 'suggest_list_to_follow' },
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
item: {
|
||||||
|
itemContent: {
|
||||||
|
list: { id_str: '999', name: 'Suggested List' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
content: {
|
||||||
|
clientEventInfo: { component: 'suggest_owned_subscribed_list' },
|
||||||
|
items: [{ item: { itemContent: { list } } }, { item: { itemContent: { list } } }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
errors: [{ message: 'optional banner field failed' }],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const client = new TwitterClient({ relayBaseUrl: testRelayBaseUrl });
|
||||||
|
const clientPrivate = client as unknown as TwitterClientPrivate;
|
||||||
|
clientPrivate.getListsManagementQueryIds = async () => ['test'];
|
||||||
|
|
||||||
|
const result = await client.getLists(100);
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
success: true,
|
||||||
|
lists: [
|
||||||
|
{
|
||||||
|
id: '1234567890',
|
||||||
|
name: 'My List',
|
||||||
|
description: 'A useful list',
|
||||||
|
memberCount: 10,
|
||||||
|
subscriberCount: undefined,
|
||||||
|
isPrivate: true,
|
||||||
|
createdAt: '2024-01-01T00:00:00.000Z',
|
||||||
|
owner: {
|
||||||
|
id: '12345',
|
||||||
|
username: 'testuser',
|
||||||
|
name: 'Test User',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const [url] = mockFetch.mock.calls[0];
|
||||||
|
const requestUrl = new URL(url as string);
|
||||||
|
expect(requestUrl.pathname).toContain('/test/ListsManagementPageTimeline');
|
||||||
|
expect(JSON.parse(requestUrl.searchParams.get('variables') as string)).toEqual({ count: 100 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns an error when the management timeline is missing', async () => {
|
||||||
|
mockFetch.mockResolvedValueOnce({
|
||||||
|
ok: true,
|
||||||
|
status: 200,
|
||||||
|
json: async () => ({ errors: [{ message: 'Not authorized' }] }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const client = new TwitterClient({ relayBaseUrl: testRelayBaseUrl });
|
||||||
|
const clientPrivate = client as unknown as TwitterClientPrivate;
|
||||||
|
clientPrivate.getListsManagementQueryIds = async () => ['test'];
|
||||||
|
|
||||||
|
await expect(client.getLists()).resolves.toEqual({
|
||||||
|
success: false,
|
||||||
|
error: 'Not authorized',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignores an invalid numeric creation date', async () => {
|
||||||
|
mockFetch.mockResolvedValueOnce({
|
||||||
|
ok: true,
|
||||||
|
status: 200,
|
||||||
|
json: async () => ({
|
||||||
|
data: {
|
||||||
|
viewer: {
|
||||||
|
list_management_timeline: {
|
||||||
|
timeline: {
|
||||||
|
instructions: [
|
||||||
|
{
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
content: {
|
||||||
|
clientEventInfo: { component: 'suggest_owned_subscribed_list' },
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
item: {
|
||||||
|
itemContent: {
|
||||||
|
list: { id_str: '123', name: 'List', created_at: Number.NaN },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const client = new TwitterClient({ relayBaseUrl: testRelayBaseUrl });
|
||||||
|
const clientPrivate = client as unknown as TwitterClientPrivate;
|
||||||
|
clientPrivate.getListsManagementQueryIds = async () => ['test'];
|
||||||
|
|
||||||
|
const result = await client.getLists();
|
||||||
|
expect(result.success && result.lists?.[0].createdAt).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -75,6 +75,9 @@ describe('TwitterClient lists memberships', () => {
|
|||||||
expect(result.lists?.[0].id).toBe('5555');
|
expect(result.lists?.[0].id).toBe('5555');
|
||||||
expect(result.lists?.[0].name).toBe('Member List');
|
expect(result.lists?.[0].name).toBe('Member List');
|
||||||
expect(result.lists?.[0].owner?.username).toBe('otheruser');
|
expect(result.lists?.[0].owner?.username).toBe('otheruser');
|
||||||
|
const [url] = mockFetch.mock.calls[0];
|
||||||
|
const variables = JSON.parse(new URL(url as string).searchParams.get('variables') as string);
|
||||||
|
expect(variables).toEqual({ userId: '12345', count: 100 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('retries on 404 error after refreshing query IDs', async () => {
|
it('retries on 404 error after refreshing query IDs', async () => {
|
||||||
|
|||||||
@@ -116,13 +116,19 @@ describe('TwitterClient lists owned', () => {
|
|||||||
await client.getOwnedLists(1);
|
await client.getOwnedLists(1);
|
||||||
|
|
||||||
const [url] = mockFetch.mock.calls[0];
|
const [url] = mockFetch.mock.calls[0];
|
||||||
const parsedFeatures = JSON.parse(new URL(url as string).searchParams.get('features') as string);
|
const requestUrl = new URL(url as string);
|
||||||
expect(parsedFeatures.responsive_web_graphql_exclude_directive_enabled).toBe(true);
|
const parsedVariables = JSON.parse(requestUrl.searchParams.get('variables') as string);
|
||||||
expect(parsedFeatures.blue_business_profile_image_shape_enabled).toBe(true);
|
const parsedFeatures = JSON.parse(requestUrl.searchParams.get('features') as string);
|
||||||
expect(parsedFeatures.responsive_web_text_conversations_enabled).toBe(false);
|
expect(parsedVariables).toEqual({
|
||||||
expect(parsedFeatures.tweetypie_unmention_optimization_enabled).toBe(true);
|
userId: '12345',
|
||||||
expect(parsedFeatures.vibe_api_enabled).toBe(true);
|
isListMemberTargetUserId: '12345',
|
||||||
expect(parsedFeatures.interactive_text_enabled).toBe(true);
|
count: 1,
|
||||||
|
});
|
||||||
|
expect(parsedFeatures.responsive_web_graphql_exclude_directive_enabled).toBeUndefined();
|
||||||
|
expect(parsedFeatures.responsive_web_grok_annotations_enabled).toBe(true);
|
||||||
|
expect(parsedFeatures.rweb_cashtags_enabled).toBe(true);
|
||||||
|
expect(parsedFeatures.responsive_web_grok_show_grok_translated_post).toBe(true);
|
||||||
|
expect(parsedFeatures.longform_notetweets_inline_media_enabled).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles private lists correctly', async () => {
|
it('handles private lists correctly', async () => {
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ describe('TwitterClient lists timeline', () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
errors: [{ message: 'optional media field failed' }],
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -6,3 +6,6 @@
|
|||||||
- When adding package registry publishing for this repository, use the `@yuta` package scope unless the user explicitly asks for another namespace.
|
- When adding package registry publishing for this repository, use the `@yuta` package scope unless the user explicitly asks for another namespace.
|
||||||
- Gitea Actions secret and variable names are case-insensitive, alphanumeric or underscore only, and cannot start with `GITEA_` or `GITHUB_`; use names like `PACKAGE_TOKEN`.
|
- Gitea Actions secret and variable names are case-insensitive, alphanumeric or underscore only, and cannot start with `GITEA_` or `GITHUB_`; use names like `PACKAGE_TOKEN`.
|
||||||
- When adapting upstream tests to this fork, run tests with `TWITTER_RELAY_BASE_URL` unset; local relay environment variables can hide missing explicit `relayBaseUrl` fixtures.
|
- When adapting upstream tests to this fork, run tests with `TWITTER_RELAY_BASE_URL` unset; local relay environment variables can hide missing explicit `relayBaseUrl` fixtures.
|
||||||
|
- For authenticated account pages, use the viewer-scoped catalog operation that
|
||||||
|
matches the UI. Do not substitute a similarly named user-scoped operation;
|
||||||
|
verify the exact request against the relay before changing Bird.
|
||||||
|
|||||||
Reference in New Issue
Block a user