dp-worker 0.1.23 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bird/ops.js +44 -0
- package/dist/bird/ops.js.map +1 -1
- package/dist/bird/sidecar-entry.js +16 -2
- package/dist/bird/sidecar-entry.js.map +1 -1
- package/dist/chrome-extension/omni-flow/manifest.json +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.d.ts +308 -0
- package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.js +228 -0
- package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts +3 -3
- package/package.json +2 -2
- package/vendor/bird/LICENSE +21 -0
- package/vendor/bird/README.md +58 -0
- package/vendor/bird/dist/cli/pagination.d.ts +35 -0
- package/vendor/bird/dist/cli/pagination.js +43 -0
- package/vendor/bird/dist/cli/program.d.ts +5 -0
- package/vendor/bird/dist/cli/program.js +113 -0
- package/vendor/bird/dist/cli/shared.d.ts +77 -0
- package/vendor/bird/dist/cli/shared.js +327 -0
- package/vendor/bird/dist/cli.d.ts +12 -0
- package/vendor/bird/dist/cli.js +29 -0
- package/vendor/bird/dist/commands/bookmarks.d.ts +4 -0
- package/vendor/bird/dist/commands/bookmarks.js +189 -0
- package/vendor/bird/dist/commands/check.d.ts +4 -0
- package/vendor/bird/dist/commands/check.js +43 -0
- package/vendor/bird/dist/commands/follow.d.ts +4 -0
- package/vendor/bird/dist/commands/follow.js +91 -0
- package/vendor/bird/dist/commands/help.d.ts +4 -0
- package/vendor/bird/dist/commands/help.js +19 -0
- package/vendor/bird/dist/commands/home.d.ts +4 -0
- package/vendor/bird/dist/commands/home.js +43 -0
- package/vendor/bird/dist/commands/lists.d.ts +4 -0
- package/vendor/bird/dist/commands/lists.js +125 -0
- package/vendor/bird/dist/commands/news.d.ts +4 -0
- package/vendor/bird/dist/commands/news.js +131 -0
- package/vendor/bird/dist/commands/post.d.ts +4 -0
- package/vendor/bird/dist/commands/post.js +101 -0
- package/vendor/bird/dist/commands/query-ids.d.ts +4 -0
- package/vendor/bird/dist/commands/query-ids.js +80 -0
- package/vendor/bird/dist/commands/read.d.ts +4 -0
- package/vendor/bird/dist/commands/read.js +152 -0
- package/vendor/bird/dist/commands/search.d.ts +4 -0
- package/vendor/bird/dist/commands/search.js +115 -0
- package/vendor/bird/dist/commands/unbookmark.d.ts +4 -0
- package/vendor/bird/dist/commands/unbookmark.js +36 -0
- package/vendor/bird/dist/commands/user-tweets.d.ts +4 -0
- package/vendor/bird/dist/commands/user-tweets.js +109 -0
- package/vendor/bird/dist/commands/users.d.ts +4 -0
- package/vendor/bird/dist/commands/users.js +295 -0
- package/vendor/bird/dist/index.d.ts +2 -0
- package/vendor/bird/dist/index.js +2 -0
- package/vendor/bird/dist/lib/cli-args.d.ts +7 -0
- package/vendor/bird/dist/lib/cli-args.js +25 -0
- package/vendor/bird/dist/lib/cookies.d.ts +31 -0
- package/vendor/bird/dist/lib/cookies.js +81 -0
- package/vendor/bird/dist/lib/extract-bookmark-folder-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-bookmark-folder-id.js +20 -0
- package/vendor/bird/dist/lib/extract-list-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-list-id.js +19 -0
- package/vendor/bird/dist/lib/extract-tweet-id.d.ts +2 -0
- package/vendor/bird/dist/lib/extract-tweet-id.js +14 -0
- package/vendor/bird/dist/lib/features.json +17 -0
- package/vendor/bird/dist/lib/index.d.ts +10 -0
- package/vendor/bird/dist/lib/index.js +4 -0
- package/vendor/bird/dist/lib/normalize-handle.d.ts +6 -0
- package/vendor/bird/dist/lib/normalize-handle.js +31 -0
- package/vendor/bird/dist/lib/output.d.ts +29 -0
- package/vendor/bird/dist/lib/output.js +88 -0
- package/vendor/bird/dist/lib/paginate-cursor.d.ts +27 -0
- package/vendor/bird/dist/lib/paginate-cursor.js +37 -0
- package/vendor/bird/dist/lib/query-ids.json +20 -0
- package/vendor/bird/dist/lib/runtime-features.d.ts +19 -0
- package/vendor/bird/dist/lib/runtime-features.js +151 -0
- package/vendor/bird/dist/lib/runtime-query-ids.d.ts +33 -0
- package/vendor/bird/dist/lib/runtime-query-ids.js +264 -0
- package/vendor/bird/dist/lib/thread-filters.d.ts +8 -0
- package/vendor/bird/dist/lib/thread-filters.js +124 -0
- package/vendor/bird/dist/lib/twitter-client-base.d.ts +38 -0
- package/vendor/bird/dist/lib/twitter-client-base.js +129 -0
- package/vendor/bird/dist/lib/twitter-client-bookmarks.d.ts +7 -0
- package/vendor/bird/dist/lib/twitter-client-bookmarks.js +61 -0
- package/vendor/bird/dist/lib/twitter-client-constants.d.ts +43 -0
- package/vendor/bird/dist/lib/twitter-client-constants.js +50 -0
- package/vendor/bird/dist/lib/twitter-client-engagement.d.ts +16 -0
- package/vendor/bird/dist/lib/twitter-client-engagement.js +81 -0
- package/vendor/bird/dist/lib/twitter-client-features.d.ts +14 -0
- package/vendor/bird/dist/lib/twitter-client-features.js +347 -0
- package/vendor/bird/dist/lib/twitter-client-follow.d.ts +8 -0
- package/vendor/bird/dist/lib/twitter-client-follow.js +178 -0
- package/vendor/bird/dist/lib/twitter-client-home.d.ts +13 -0
- package/vendor/bird/dist/lib/twitter-client-home.js +138 -0
- package/vendor/bird/dist/lib/twitter-client-lists.d.ts +11 -0
- package/vendor/bird/dist/lib/twitter-client-lists.js +321 -0
- package/vendor/bird/dist/lib/twitter-client-media.d.ts +11 -0
- package/vendor/bird/dist/lib/twitter-client-media.js +136 -0
- package/vendor/bird/dist/lib/twitter-client-news.d.ts +47 -0
- package/vendor/bird/dist/lib/twitter-client-news.js +283 -0
- package/vendor/bird/dist/lib/twitter-client-posting.d.ts +8 -0
- package/vendor/bird/dist/lib/twitter-client-posting.js +218 -0
- package/vendor/bird/dist/lib/twitter-client-search.d.ts +19 -0
- package/vendor/bird/dist/lib/twitter-client-search.js +157 -0
- package/vendor/bird/dist/lib/twitter-client-timelines.d.ts +23 -0
- package/vendor/bird/dist/lib/twitter-client-timelines.js +471 -0
- package/vendor/bird/dist/lib/twitter-client-tweet-detail.d.ts +25 -0
- package/vendor/bird/dist/lib/twitter-client-tweet-detail.js +295 -0
- package/vendor/bird/dist/lib/twitter-client-types.d.ts +407 -0
- package/vendor/bird/dist/lib/twitter-client-types.js +2 -0
- package/vendor/bird/dist/lib/twitter-client-user-lookup.d.ts +16 -0
- package/vendor/bird/dist/lib/twitter-client-user-lookup.js +224 -0
- package/vendor/bird/dist/lib/twitter-client-user-tweets.d.ts +22 -0
- package/vendor/bird/dist/lib/twitter-client-user-tweets.js +154 -0
- package/vendor/bird/dist/lib/twitter-client-users.d.ts +9 -0
- package/vendor/bird/dist/lib/twitter-client-users.js +358 -0
- package/vendor/bird/dist/lib/twitter-client-utils.d.ts +173 -0
- package/vendor/bird/dist/lib/twitter-client-utils.js +511 -0
- package/vendor/bird/dist/lib/twitter-client.d.ts +23 -0
- package/vendor/bird/dist/lib/twitter-client.js +21 -0
- package/vendor/bird/dist/lib/version.d.ts +6 -0
- package/vendor/bird/dist/lib/version.js +174 -0
- package/vendor/bird/upstream-package.json +61 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { parsePaginationFlags } from '../cli/pagination.js';
|
|
2
|
+
import { extractBookmarkFolderId } from '../lib/extract-bookmark-folder-id.js';
|
|
3
|
+
import { addThreadMetadata, filterAuthorChain, filterAuthorOnly, filterFullChain } from '../lib/thread-filters.js';
|
|
4
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
5
|
+
export function registerBookmarksCommand(program, ctx) {
|
|
6
|
+
program
|
|
7
|
+
.command('bookmarks')
|
|
8
|
+
.description('Get your bookmarked tweets')
|
|
9
|
+
.option('-n, --count <number>', 'Number of bookmarks to fetch', '20')
|
|
10
|
+
.option('--folder-id <id>', 'Bookmark folder (collection) id')
|
|
11
|
+
.option('--all', 'Fetch all bookmarks (paged)')
|
|
12
|
+
.option('--max-pages <number>', 'Stop after N pages when using --all')
|
|
13
|
+
.option('--cursor <string>', 'Resume pagination from a cursor')
|
|
14
|
+
.option('--expand-root-only', 'Only expand threads when bookmarked tweet is root')
|
|
15
|
+
.option('--author-chain', 'Only include author self-reply chains connected to the bookmark')
|
|
16
|
+
.option('--author-only', 'Include all tweets from bookmarked tweet author in thread')
|
|
17
|
+
.option('--full-chain-only', 'Save entire reply chain connected to the bookmarked tweet')
|
|
18
|
+
.option('--include-ancestor-branches', 'Include sibling branches for ancestors when using --full-chain-only')
|
|
19
|
+
.option('--include-parent', 'Include direct parent tweet for non-root bookmarks')
|
|
20
|
+
.option('--thread-meta', 'Add metadata fields (isThread, threadPosition, etc.)')
|
|
21
|
+
.option('--sort-chronological', 'Sort output globally oldest -> newest')
|
|
22
|
+
.option('--json', 'Output as JSON')
|
|
23
|
+
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
|
24
|
+
.action(async (cmdOpts) => {
|
|
25
|
+
const opts = program.opts();
|
|
26
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
27
|
+
const count = Number.parseInt(cmdOpts.count || '20', 10);
|
|
28
|
+
const pagination = parsePaginationFlags(cmdOpts);
|
|
29
|
+
if (!pagination.ok) {
|
|
30
|
+
console.error(`${ctx.p('err')}${pagination.error}`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
const maxPages = pagination.maxPages;
|
|
34
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
35
|
+
for (const warning of warnings) {
|
|
36
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
37
|
+
}
|
|
38
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
39
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
const usePagination = pagination.usePagination;
|
|
43
|
+
if (maxPages !== undefined && !usePagination) {
|
|
44
|
+
console.error(`${ctx.p('err')}--max-pages requires --all or --cursor.`);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
if (!usePagination && (!Number.isFinite(count) || count <= 0)) {
|
|
48
|
+
console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const client = new TwitterClient({ cookies, timeoutMs });
|
|
52
|
+
const folderId = cmdOpts.folderId ? extractBookmarkFolderId(cmdOpts.folderId) : null;
|
|
53
|
+
if (cmdOpts.folderId && !folderId) {
|
|
54
|
+
console.error(`${ctx.p('err')}Invalid --folder-id. Expected numeric ID or https://x.com/i/bookmarks/<id>.`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
const includeRaw = cmdOpts.jsonFull ?? false;
|
|
58
|
+
const timelineOptions = { includeRaw };
|
|
59
|
+
const paginationOptions = { includeRaw, maxPages, cursor: pagination.cursor };
|
|
60
|
+
const result = folderId
|
|
61
|
+
? usePagination
|
|
62
|
+
? await client.getAllBookmarkFolderTimeline(folderId, paginationOptions)
|
|
63
|
+
: await client.getBookmarkFolderTimeline(folderId, count, timelineOptions)
|
|
64
|
+
: usePagination
|
|
65
|
+
? await client.getAllBookmarks(paginationOptions)
|
|
66
|
+
: await client.getBookmarks(count, timelineOptions);
|
|
67
|
+
if (!result.success) {
|
|
68
|
+
console.error(`${ctx.p('err')}Failed to fetch bookmarks: ${result.error}`);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
if (cmdOpts.authorChain && (cmdOpts.authorOnly || cmdOpts.fullChainOnly)) {
|
|
72
|
+
console.error(`${ctx.p('warn')}--author-chain already limits to the connected self-reply chain; ` +
|
|
73
|
+
'other chain filters are redundant.');
|
|
74
|
+
}
|
|
75
|
+
if (cmdOpts.includeAncestorBranches && !cmdOpts.fullChainOnly) {
|
|
76
|
+
console.error(`${ctx.p('warn')}--include-ancestor-branches only applies with --full-chain-only.`);
|
|
77
|
+
}
|
|
78
|
+
const bookmarks = result.tweets;
|
|
79
|
+
if (!bookmarks || bookmarks.length === 0) {
|
|
80
|
+
const emptyMessage = folderId ? 'No bookmarks found in folder.' : 'No bookmarks found.';
|
|
81
|
+
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
|
82
|
+
ctx.printTweetsResult(result, { json: isJson, usePagination, emptyMessage });
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const expandedResults = [];
|
|
86
|
+
const threadCache = new Map();
|
|
87
|
+
const includeMeta = Boolean(cmdOpts.threadMeta);
|
|
88
|
+
const includeParent = Boolean(cmdOpts.includeParent);
|
|
89
|
+
const expandRootOnly = Boolean(cmdOpts.expandRootOnly);
|
|
90
|
+
const filterAuthorChainFlag = Boolean(cmdOpts.authorChain);
|
|
91
|
+
const filterAuthorOnlyFlag = Boolean(cmdOpts.authorOnly);
|
|
92
|
+
const filterFullChainFlag = Boolean(cmdOpts.fullChainOnly);
|
|
93
|
+
const includeAncestorBranches = Boolean(cmdOpts.includeAncestorBranches) && filterFullChainFlag;
|
|
94
|
+
const useChronologicalSort = Boolean(cmdOpts.sortChronological);
|
|
95
|
+
const shouldAttemptExpand = expandRootOnly || filterAuthorChainFlag || filterAuthorOnlyFlag || filterFullChainFlag;
|
|
96
|
+
const shouldFetchThread = shouldAttemptExpand || includeMeta;
|
|
97
|
+
const fetchThread = async (tweet) => {
|
|
98
|
+
const cachedKey = tweet.conversationId ?? tweet.id;
|
|
99
|
+
const cached = threadCache.get(cachedKey);
|
|
100
|
+
if (cached) {
|
|
101
|
+
return cached;
|
|
102
|
+
}
|
|
103
|
+
const threadResult = await client.getThread(tweet.id, { includeRaw });
|
|
104
|
+
if (!threadResult.success) {
|
|
105
|
+
console.error(`${ctx.p('warn')}Failed to expand thread for ${tweet.id}: ${threadResult.error ?? 'Unknown error'}`);
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
if (!threadResult.tweets) {
|
|
109
|
+
console.error(`${ctx.p('warn')}No thread tweets returned for ${tweet.id}.`);
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const rootKey = threadResult.tweets[0]?.conversationId ?? cachedKey;
|
|
113
|
+
threadCache.set(rootKey, threadResult.tweets);
|
|
114
|
+
return threadResult.tweets;
|
|
115
|
+
};
|
|
116
|
+
const delayBetweenExpansionsMs = 1000;
|
|
117
|
+
for (let index = 0; index < bookmarks.length; index += 1) {
|
|
118
|
+
const bookmark = bookmarks[index];
|
|
119
|
+
const isRoot = !bookmark.inReplyToStatusId;
|
|
120
|
+
let threadTweets = null;
|
|
121
|
+
if (shouldFetchThread) {
|
|
122
|
+
if (!expandRootOnly || isRoot || includeMeta) {
|
|
123
|
+
if (index > 0) {
|
|
124
|
+
await new Promise((resolve) => setTimeout(resolve, delayBetweenExpansionsMs));
|
|
125
|
+
}
|
|
126
|
+
threadTweets = await fetchThread(bookmark);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
let outputTweets = [bookmark];
|
|
130
|
+
if (shouldAttemptExpand) {
|
|
131
|
+
if (expandRootOnly && !isRoot) {
|
|
132
|
+
outputTweets = [bookmark];
|
|
133
|
+
}
|
|
134
|
+
else if (threadTweets) {
|
|
135
|
+
if (filterAuthorChainFlag) {
|
|
136
|
+
outputTweets = filterAuthorChain(threadTweets, bookmark);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
outputTweets = filterFullChainFlag
|
|
140
|
+
? filterFullChain(threadTweets, bookmark, { includeAncestorBranches })
|
|
141
|
+
: threadTweets;
|
|
142
|
+
if (filterAuthorOnlyFlag) {
|
|
143
|
+
outputTweets = filterAuthorOnly(outputTweets, bookmark);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (includeParent && bookmark.inReplyToStatusId) {
|
|
149
|
+
const alreadyIncluded = outputTweets.some((tweet) => tweet.id === bookmark.inReplyToStatusId);
|
|
150
|
+
if (!alreadyIncluded) {
|
|
151
|
+
const parentFromThread = threadTweets?.find((tweet) => tweet.id === bookmark.inReplyToStatusId);
|
|
152
|
+
if (parentFromThread) {
|
|
153
|
+
expandedResults.push(parentFromThread);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
const parentResult = await client.getTweet(bookmark.inReplyToStatusId, { includeRaw });
|
|
157
|
+
if (parentResult.success && parentResult.tweet) {
|
|
158
|
+
expandedResults.push(parentResult.tweet);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
expandedResults.push(...outputTweets);
|
|
164
|
+
}
|
|
165
|
+
let finalResults = expandedResults;
|
|
166
|
+
if (includeMeta) {
|
|
167
|
+
finalResults = expandedResults.map((tweet) => {
|
|
168
|
+
const cacheKey = tweet.conversationId ?? tweet.id;
|
|
169
|
+
let conversationTweets = threadCache.get(cacheKey);
|
|
170
|
+
if (!conversationTweets) {
|
|
171
|
+
conversationTweets = [tweet];
|
|
172
|
+
}
|
|
173
|
+
return addThreadMetadata(tweet, conversationTweets);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
const uniqueTweets = Array.from(new Map(finalResults.map((tweet) => [tweet.id, tweet])).values());
|
|
177
|
+
if (useChronologicalSort) {
|
|
178
|
+
uniqueTweets.sort((a, b) => {
|
|
179
|
+
const aTime = a.createdAt ? Date.parse(a.createdAt) : 0;
|
|
180
|
+
const bTime = b.createdAt ? Date.parse(b.createdAt) : 0;
|
|
181
|
+
return aTime - bTime;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
const emptyMessage = folderId ? 'No bookmarks found in folder.' : 'No bookmarks found.';
|
|
185
|
+
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
|
186
|
+
ctx.printTweetsResult({ tweets: uniqueTweets, nextCursor: result.nextCursor }, { json: isJson, usePagination, emptyMessage });
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=bookmarks.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function registerCheckCommand(program, ctx) {
|
|
2
|
+
program
|
|
3
|
+
.command('check')
|
|
4
|
+
.description('Check credential availability')
|
|
5
|
+
.action(async () => {
|
|
6
|
+
const opts = program.opts();
|
|
7
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
8
|
+
console.log(`${ctx.p('info')}Credential check`);
|
|
9
|
+
console.log('─'.repeat(40));
|
|
10
|
+
if (cookies.authToken) {
|
|
11
|
+
console.log(`${ctx.p('ok')}auth_token: ${cookies.authToken.slice(0, 10)}...`);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
console.log(`${ctx.p('err')}auth_token: not found`);
|
|
15
|
+
}
|
|
16
|
+
if (cookies.ct0) {
|
|
17
|
+
console.log(`${ctx.p('ok')}ct0: ${cookies.ct0.slice(0, 10)}...`);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
console.log(`${ctx.p('err')}ct0: not found`);
|
|
21
|
+
}
|
|
22
|
+
if (cookies.source) {
|
|
23
|
+
console.log(`${ctx.l('source')}${cookies.source}`);
|
|
24
|
+
}
|
|
25
|
+
if (warnings.length > 0) {
|
|
26
|
+
console.log(`\n${ctx.p('warn')}Warnings:`);
|
|
27
|
+
for (const warning of warnings) {
|
|
28
|
+
console.log(` - ${warning}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (cookies.authToken && cookies.ct0) {
|
|
32
|
+
console.log(`\n${ctx.p('ok')}Ready to tweet!`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.log(`\n${ctx.p('err')}Missing credentials. Options:`);
|
|
36
|
+
console.log(' 1. Login to x.com in Safari/Chrome/Firefox');
|
|
37
|
+
console.log(' 2. Set AUTH_TOKEN and CT0 environment variables');
|
|
38
|
+
console.log(' 3. Use --auth-token and --ct0 flags');
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { normalizeHandle } from '../lib/normalize-handle.js';
|
|
2
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
3
|
+
const ONLY_DIGITS_REGEX = /^\d+$/;
|
|
4
|
+
async function resolveUserId(client, usernameOrId, ctx) {
|
|
5
|
+
const raw = usernameOrId.trim();
|
|
6
|
+
const isNumeric = ONLY_DIGITS_REGEX.test(raw);
|
|
7
|
+
// Otherwise, treat as username and look up
|
|
8
|
+
const handle = normalizeHandle(raw);
|
|
9
|
+
if (handle) {
|
|
10
|
+
const lookup = await client.getUserIdByUsername(handle);
|
|
11
|
+
if (lookup.success && lookup.userId) {
|
|
12
|
+
return { userId: lookup.userId, username: lookup.username };
|
|
13
|
+
}
|
|
14
|
+
if (!isNumeric) {
|
|
15
|
+
console.error(`${ctx.p('err')}Failed to find user @${handle}: ${lookup.error ?? 'Unknown error'}`);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (isNumeric) {
|
|
20
|
+
return { userId: raw };
|
|
21
|
+
}
|
|
22
|
+
console.error(`${ctx.p('err')}Invalid username: ${usernameOrId}`);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
export function registerFollowCommands(program, ctx) {
|
|
26
|
+
program
|
|
27
|
+
.command('follow')
|
|
28
|
+
.description('Follow a user')
|
|
29
|
+
.argument('<username-or-id>', 'Username (with or without @) or user ID to follow')
|
|
30
|
+
.action(async (usernameOrId) => {
|
|
31
|
+
const opts = program.opts();
|
|
32
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
33
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
34
|
+
for (const warning of warnings) {
|
|
35
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
36
|
+
}
|
|
37
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
38
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
const client = new TwitterClient({ cookies, timeoutMs });
|
|
42
|
+
const resolved = await resolveUserId(client, usernameOrId, ctx);
|
|
43
|
+
if (!resolved) {
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
const { userId, username } = resolved;
|
|
47
|
+
const displayName = username ? `@${username}` : userId;
|
|
48
|
+
const result = await client.follow(userId);
|
|
49
|
+
if (result.success) {
|
|
50
|
+
const finalName = result.username ? `@${result.username}` : displayName;
|
|
51
|
+
console.log(`${ctx.p('ok')}Now following ${finalName}`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.error(`${ctx.p('err')}Failed to follow ${displayName}: ${result.error}`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
program
|
|
59
|
+
.command('unfollow')
|
|
60
|
+
.description('Unfollow a user')
|
|
61
|
+
.argument('<username-or-id>', 'Username (with or without @) or user ID to unfollow')
|
|
62
|
+
.action(async (usernameOrId) => {
|
|
63
|
+
const opts = program.opts();
|
|
64
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
65
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
66
|
+
for (const warning of warnings) {
|
|
67
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
68
|
+
}
|
|
69
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
70
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
const client = new TwitterClient({ cookies, timeoutMs });
|
|
74
|
+
const resolved = await resolveUserId(client, usernameOrId, ctx);
|
|
75
|
+
if (!resolved) {
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
const { userId, username } = resolved;
|
|
79
|
+
const displayName = username ? `@${username}` : userId;
|
|
80
|
+
const result = await client.unfollow(userId);
|
|
81
|
+
if (result.success) {
|
|
82
|
+
const finalName = result.username ? `@${result.username}` : displayName;
|
|
83
|
+
console.log(`${ctx.p('ok')}Unfollowed ${finalName}`);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.error(`${ctx.p('err')}Failed to unfollow ${displayName}: ${result.error}`);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=follow.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function registerHelpCommand(program, ctx) {
|
|
2
|
+
program
|
|
3
|
+
.command('help [command]')
|
|
4
|
+
.description('Show help for a command')
|
|
5
|
+
.action((commandName) => {
|
|
6
|
+
if (!commandName) {
|
|
7
|
+
program.outputHelp();
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const cmd = program.commands.find((c) => c.name() === commandName);
|
|
11
|
+
if (!cmd) {
|
|
12
|
+
console.error(`${ctx.p('err')}Unknown command: ${commandName}`);
|
|
13
|
+
process.exitCode = 2;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
cmd.outputHelp();
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=help.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
2
|
+
export function registerHomeCommand(program, ctx) {
|
|
3
|
+
program
|
|
4
|
+
.command('home')
|
|
5
|
+
.description('Get your home timeline ("For You" feed)')
|
|
6
|
+
.option('-n, --count <number>', 'Number of tweets to fetch', '20')
|
|
7
|
+
.option('--following', 'Get "Following" feed (chronological) instead of "For You"')
|
|
8
|
+
.option('--json', 'Output as JSON')
|
|
9
|
+
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
|
10
|
+
.action(async (cmdOpts) => {
|
|
11
|
+
const opts = program.opts();
|
|
12
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
13
|
+
const count = Number.parseInt(cmdOpts.count || '20', 10);
|
|
14
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
15
|
+
for (const warning of warnings) {
|
|
16
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
17
|
+
}
|
|
18
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
19
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
if (!Number.isFinite(count) || count <= 0) {
|
|
23
|
+
console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
const client = new TwitterClient({ cookies, timeoutMs });
|
|
27
|
+
const includeRaw = cmdOpts.jsonFull ?? false;
|
|
28
|
+
const result = cmdOpts.following
|
|
29
|
+
? await client.getHomeLatestTimeline(count, { includeRaw })
|
|
30
|
+
: await client.getHomeTimeline(count, { includeRaw });
|
|
31
|
+
if (result.success) {
|
|
32
|
+
const feedType = cmdOpts.following ? 'Following' : 'For You';
|
|
33
|
+
const emptyMessage = `No tweets found in ${feedType} timeline.`;
|
|
34
|
+
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
|
35
|
+
ctx.printTweets(result.tweets, { json: isJson, emptyMessage });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.error(`${ctx.p('err')}Failed to fetch home timeline: ${result.error}`);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=home.js.map
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// ABOUTME: CLI command for fetching Twitter Lists.
|
|
2
|
+
// ABOUTME: Supports listing owned lists, memberships, and list timelines.
|
|
3
|
+
import { parsePaginationFlags } from '../cli/pagination.js';
|
|
4
|
+
import { extractListId } from '../lib/extract-list-id.js';
|
|
5
|
+
import { hyperlink } from '../lib/output.js';
|
|
6
|
+
import { TwitterClient } from '../lib/twitter-client.js';
|
|
7
|
+
function printLists(lists, ctx) {
|
|
8
|
+
if (lists.length === 0) {
|
|
9
|
+
console.log('No lists found.');
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
for (const list of lists) {
|
|
13
|
+
const visibility = list.isPrivate ? '[private]' : '[public]';
|
|
14
|
+
console.log(`${list.name} ${ctx.colors.muted(visibility)}`);
|
|
15
|
+
if (list.description) {
|
|
16
|
+
console.log(` ${list.description.slice(0, 100)}${list.description.length > 100 ? '...' : ''}`);
|
|
17
|
+
}
|
|
18
|
+
console.log(` ${ctx.p('info')}${list.memberCount?.toLocaleString() ?? 0} members`);
|
|
19
|
+
if (list.owner) {
|
|
20
|
+
console.log(` ${ctx.colors.muted(`Owner: @${list.owner.username}`)}`);
|
|
21
|
+
}
|
|
22
|
+
const listUrl = `https://x.com/i/lists/${list.id}`;
|
|
23
|
+
console.log(` ${ctx.colors.accent(hyperlink(listUrl, listUrl, ctx.getOutput()))}`);
|
|
24
|
+
console.log('──────────────────────────────────────────────────');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function registerListsCommand(program, ctx) {
|
|
28
|
+
program
|
|
29
|
+
.command('lists')
|
|
30
|
+
.description('Get your Twitter lists')
|
|
31
|
+
.option('--member-of', 'Show lists you are a member of (instead of owned lists)')
|
|
32
|
+
.option('-n, --count <number>', 'Number of lists to fetch', '100')
|
|
33
|
+
.option('--json', 'Output as JSON')
|
|
34
|
+
.action(async (cmdOpts) => {
|
|
35
|
+
const opts = program.opts();
|
|
36
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
37
|
+
const count = Number.parseInt(cmdOpts.count || '100', 10);
|
|
38
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
39
|
+
for (const warning of warnings) {
|
|
40
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
41
|
+
}
|
|
42
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
43
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
const client = new TwitterClient({ cookies, timeoutMs });
|
|
47
|
+
const result = cmdOpts.memberOf ? await client.getListMemberships(count) : await client.getOwnedLists(count);
|
|
48
|
+
if (result.success && result.lists) {
|
|
49
|
+
if (cmdOpts.json) {
|
|
50
|
+
console.log(JSON.stringify(result.lists, null, 2));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const emptyMessage = cmdOpts.memberOf ? 'You are not a member of any lists.' : 'You do not own any lists.';
|
|
54
|
+
if (result.lists.length === 0) {
|
|
55
|
+
console.log(emptyMessage);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
printLists(result.lists, ctx);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.error(`${ctx.p('err')}Failed to fetch lists: ${result.error}`);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
program
|
|
68
|
+
.command('list-timeline <list-id-or-url>')
|
|
69
|
+
.description('Get tweets from a list timeline')
|
|
70
|
+
.option('-n, --count <number>', 'Number of tweets to fetch', '20')
|
|
71
|
+
.option('--all', 'Fetch all tweets from list (paged). WARNING: your account might get banned using this flag')
|
|
72
|
+
.option('--max-pages <number>', 'Fetch N pages (implies --all)')
|
|
73
|
+
.option('--cursor <string>', 'Resume pagination from a cursor')
|
|
74
|
+
.option('--json', 'Output as JSON')
|
|
75
|
+
.option('--json-full', 'Output as JSON with full raw API response in _raw field')
|
|
76
|
+
.action(async (listIdOrUrl, cmdOpts) => {
|
|
77
|
+
const opts = program.opts();
|
|
78
|
+
const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
|
|
79
|
+
const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
|
|
80
|
+
const count = Number.parseInt(cmdOpts.count || '20', 10);
|
|
81
|
+
const pagination = parsePaginationFlags(cmdOpts, { maxPagesImpliesPagination: true });
|
|
82
|
+
if (!pagination.ok) {
|
|
83
|
+
console.error(`${ctx.p('err')}${pagination.error}`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
const listId = extractListId(listIdOrUrl);
|
|
87
|
+
if (!listId) {
|
|
88
|
+
console.error(`${ctx.p('err')}Invalid list ID or URL. Expected numeric ID or https://x.com/i/lists/<id>.`);
|
|
89
|
+
process.exit(2);
|
|
90
|
+
}
|
|
91
|
+
const usePagination = pagination.usePagination;
|
|
92
|
+
if (!usePagination && (!Number.isFinite(count) || count <= 0)) {
|
|
93
|
+
console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
|
|
97
|
+
for (const warning of warnings) {
|
|
98
|
+
console.error(`${ctx.p('warn')}${warning}`);
|
|
99
|
+
}
|
|
100
|
+
if (!cookies.authToken || !cookies.ct0) {
|
|
101
|
+
console.error(`${ctx.p('err')}Missing required credentials`);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
|
|
105
|
+
const includeRaw = cmdOpts.jsonFull ?? false;
|
|
106
|
+
const timelineOptions = { includeRaw };
|
|
107
|
+
const paginationOptions = { includeRaw, maxPages: pagination.maxPages, cursor: pagination.cursor };
|
|
108
|
+
const result = usePagination
|
|
109
|
+
? await client.getAllListTimeline(listId, paginationOptions)
|
|
110
|
+
: await client.getListTimeline(listId, count, timelineOptions);
|
|
111
|
+
if (result.success) {
|
|
112
|
+
const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
|
|
113
|
+
ctx.printTweetsResult(result, {
|
|
114
|
+
json: isJson,
|
|
115
|
+
usePagination,
|
|
116
|
+
emptyMessage: 'No tweets found in this list.',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
console.error(`${ctx.p('err')}Failed to fetch list timeline: ${result.error}`);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=lists.js.map
|