dp-worker 0.1.23 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/bird/ops.js +44 -0
  2. package/dist/bird/ops.js.map +1 -1
  3. package/dist/bird/sidecar-entry.js +16 -2
  4. package/dist/bird/sidecar-entry.js.map +1 -1
  5. package/dist/chrome-extension/omni-flow/manifest.json +1 -1
  6. package/node_modules/dp-shared/dist/bird-contracts.d.ts +308 -0
  7. package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
  8. package/node_modules/dp-shared/dist/bird-contracts.js +228 -0
  9. package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
  10. package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts +3 -3
  11. package/package.json +2 -2
  12. package/vendor/bird/LICENSE +21 -0
  13. package/vendor/bird/README.md +58 -0
  14. package/vendor/bird/dist/cli/pagination.d.ts +35 -0
  15. package/vendor/bird/dist/cli/pagination.js +43 -0
  16. package/vendor/bird/dist/cli/program.d.ts +5 -0
  17. package/vendor/bird/dist/cli/program.js +113 -0
  18. package/vendor/bird/dist/cli/shared.d.ts +77 -0
  19. package/vendor/bird/dist/cli/shared.js +327 -0
  20. package/vendor/bird/dist/cli.d.ts +12 -0
  21. package/vendor/bird/dist/cli.js +29 -0
  22. package/vendor/bird/dist/commands/bookmarks.d.ts +4 -0
  23. package/vendor/bird/dist/commands/bookmarks.js +189 -0
  24. package/vendor/bird/dist/commands/check.d.ts +4 -0
  25. package/vendor/bird/dist/commands/check.js +43 -0
  26. package/vendor/bird/dist/commands/follow.d.ts +4 -0
  27. package/vendor/bird/dist/commands/follow.js +91 -0
  28. package/vendor/bird/dist/commands/help.d.ts +4 -0
  29. package/vendor/bird/dist/commands/help.js +19 -0
  30. package/vendor/bird/dist/commands/home.d.ts +4 -0
  31. package/vendor/bird/dist/commands/home.js +43 -0
  32. package/vendor/bird/dist/commands/lists.d.ts +4 -0
  33. package/vendor/bird/dist/commands/lists.js +125 -0
  34. package/vendor/bird/dist/commands/news.d.ts +4 -0
  35. package/vendor/bird/dist/commands/news.js +131 -0
  36. package/vendor/bird/dist/commands/post.d.ts +4 -0
  37. package/vendor/bird/dist/commands/post.js +101 -0
  38. package/vendor/bird/dist/commands/query-ids.d.ts +4 -0
  39. package/vendor/bird/dist/commands/query-ids.js +80 -0
  40. package/vendor/bird/dist/commands/read.d.ts +4 -0
  41. package/vendor/bird/dist/commands/read.js +152 -0
  42. package/vendor/bird/dist/commands/search.d.ts +4 -0
  43. package/vendor/bird/dist/commands/search.js +115 -0
  44. package/vendor/bird/dist/commands/unbookmark.d.ts +4 -0
  45. package/vendor/bird/dist/commands/unbookmark.js +36 -0
  46. package/vendor/bird/dist/commands/user-tweets.d.ts +4 -0
  47. package/vendor/bird/dist/commands/user-tweets.js +109 -0
  48. package/vendor/bird/dist/commands/users.d.ts +4 -0
  49. package/vendor/bird/dist/commands/users.js +295 -0
  50. package/vendor/bird/dist/index.d.ts +2 -0
  51. package/vendor/bird/dist/index.js +2 -0
  52. package/vendor/bird/dist/lib/cli-args.d.ts +7 -0
  53. package/vendor/bird/dist/lib/cli-args.js +25 -0
  54. package/vendor/bird/dist/lib/cookies.d.ts +31 -0
  55. package/vendor/bird/dist/lib/cookies.js +81 -0
  56. package/vendor/bird/dist/lib/extract-bookmark-folder-id.d.ts +2 -0
  57. package/vendor/bird/dist/lib/extract-bookmark-folder-id.js +20 -0
  58. package/vendor/bird/dist/lib/extract-list-id.d.ts +2 -0
  59. package/vendor/bird/dist/lib/extract-list-id.js +19 -0
  60. package/vendor/bird/dist/lib/extract-tweet-id.d.ts +2 -0
  61. package/vendor/bird/dist/lib/extract-tweet-id.js +14 -0
  62. package/vendor/bird/dist/lib/features.json +17 -0
  63. package/vendor/bird/dist/lib/index.d.ts +10 -0
  64. package/vendor/bird/dist/lib/index.js +4 -0
  65. package/vendor/bird/dist/lib/normalize-handle.d.ts +6 -0
  66. package/vendor/bird/dist/lib/normalize-handle.js +31 -0
  67. package/vendor/bird/dist/lib/output.d.ts +29 -0
  68. package/vendor/bird/dist/lib/output.js +88 -0
  69. package/vendor/bird/dist/lib/paginate-cursor.d.ts +27 -0
  70. package/vendor/bird/dist/lib/paginate-cursor.js +37 -0
  71. package/vendor/bird/dist/lib/query-ids.json +20 -0
  72. package/vendor/bird/dist/lib/runtime-features.d.ts +19 -0
  73. package/vendor/bird/dist/lib/runtime-features.js +151 -0
  74. package/vendor/bird/dist/lib/runtime-query-ids.d.ts +33 -0
  75. package/vendor/bird/dist/lib/runtime-query-ids.js +264 -0
  76. package/vendor/bird/dist/lib/thread-filters.d.ts +8 -0
  77. package/vendor/bird/dist/lib/thread-filters.js +124 -0
  78. package/vendor/bird/dist/lib/twitter-client-base.d.ts +38 -0
  79. package/vendor/bird/dist/lib/twitter-client-base.js +129 -0
  80. package/vendor/bird/dist/lib/twitter-client-bookmarks.d.ts +7 -0
  81. package/vendor/bird/dist/lib/twitter-client-bookmarks.js +61 -0
  82. package/vendor/bird/dist/lib/twitter-client-constants.d.ts +43 -0
  83. package/vendor/bird/dist/lib/twitter-client-constants.js +50 -0
  84. package/vendor/bird/dist/lib/twitter-client-engagement.d.ts +16 -0
  85. package/vendor/bird/dist/lib/twitter-client-engagement.js +81 -0
  86. package/vendor/bird/dist/lib/twitter-client-features.d.ts +14 -0
  87. package/vendor/bird/dist/lib/twitter-client-features.js +347 -0
  88. package/vendor/bird/dist/lib/twitter-client-follow.d.ts +8 -0
  89. package/vendor/bird/dist/lib/twitter-client-follow.js +178 -0
  90. package/vendor/bird/dist/lib/twitter-client-home.d.ts +13 -0
  91. package/vendor/bird/dist/lib/twitter-client-home.js +138 -0
  92. package/vendor/bird/dist/lib/twitter-client-lists.d.ts +11 -0
  93. package/vendor/bird/dist/lib/twitter-client-lists.js +321 -0
  94. package/vendor/bird/dist/lib/twitter-client-media.d.ts +11 -0
  95. package/vendor/bird/dist/lib/twitter-client-media.js +136 -0
  96. package/vendor/bird/dist/lib/twitter-client-news.d.ts +47 -0
  97. package/vendor/bird/dist/lib/twitter-client-news.js +283 -0
  98. package/vendor/bird/dist/lib/twitter-client-posting.d.ts +8 -0
  99. package/vendor/bird/dist/lib/twitter-client-posting.js +218 -0
  100. package/vendor/bird/dist/lib/twitter-client-search.d.ts +19 -0
  101. package/vendor/bird/dist/lib/twitter-client-search.js +157 -0
  102. package/vendor/bird/dist/lib/twitter-client-timelines.d.ts +23 -0
  103. package/vendor/bird/dist/lib/twitter-client-timelines.js +471 -0
  104. package/vendor/bird/dist/lib/twitter-client-tweet-detail.d.ts +25 -0
  105. package/vendor/bird/dist/lib/twitter-client-tweet-detail.js +295 -0
  106. package/vendor/bird/dist/lib/twitter-client-types.d.ts +407 -0
  107. package/vendor/bird/dist/lib/twitter-client-types.js +2 -0
  108. package/vendor/bird/dist/lib/twitter-client-user-lookup.d.ts +16 -0
  109. package/vendor/bird/dist/lib/twitter-client-user-lookup.js +224 -0
  110. package/vendor/bird/dist/lib/twitter-client-user-tweets.d.ts +22 -0
  111. package/vendor/bird/dist/lib/twitter-client-user-tweets.js +154 -0
  112. package/vendor/bird/dist/lib/twitter-client-users.d.ts +9 -0
  113. package/vendor/bird/dist/lib/twitter-client-users.js +358 -0
  114. package/vendor/bird/dist/lib/twitter-client-utils.d.ts +173 -0
  115. package/vendor/bird/dist/lib/twitter-client-utils.js +511 -0
  116. package/vendor/bird/dist/lib/twitter-client.d.ts +23 -0
  117. package/vendor/bird/dist/lib/twitter-client.js +21 -0
  118. package/vendor/bird/dist/lib/version.d.ts +6 -0
  119. package/vendor/bird/dist/lib/version.js +174 -0
  120. package/vendor/bird/upstream-package.json +61 -0
@@ -0,0 +1,109 @@
1
+ import { parseNonNegativeIntFlag, parsePositiveIntFlag } from '../cli/pagination.js';
2
+ import { normalizeHandle } from '../lib/normalize-handle.js';
3
+ import { TwitterClient } from '../lib/twitter-client.js';
4
+ export function registerUserTweetsCommand(program, ctx) {
5
+ const formatExample = (cmd, desc) => ` ${ctx.colors.command(cmd)}\n ${ctx.colors.muted(desc)}`;
6
+ program
7
+ .command('user-tweets')
8
+ .description("Get tweets from a user's profile timeline")
9
+ .argument('<handle>', 'Username to fetch tweets from (e.g., @steipete or steipete)')
10
+ .option('-n, --count <number>', 'Number of tweets to fetch', '20')
11
+ .option('--max-pages <number>', 'Stop after N pages (max: 10)')
12
+ .option('--delay <ms>', 'Delay in ms between page fetches', '1000')
13
+ .option('--cursor <string>', 'Resume pagination from a cursor')
14
+ .option('--json', 'Output as JSON')
15
+ .option('--json-full', 'Output as JSON with full raw API response in _raw field')
16
+ .addHelpText('after', () => `\n${ctx.colors.section('Command Examples')}\n${[
17
+ formatExample('bird user-tweets @steipete', 'Get recent tweets from a user'),
18
+ formatExample('bird user-tweets steipete -n 10', 'Get 10 tweets (@ is optional)'),
19
+ formatExample('bird user-tweets @steipete -n 50', 'Fetch 50 tweets (paged)'),
20
+ formatExample('bird user-tweets @steipete --max-pages 3 -n 200', 'Safety cap (max 3 pages)'),
21
+ formatExample('bird user-tweets @steipete --json', 'Output as JSON'),
22
+ formatExample('bird user-tweets @steipete --cursor "DAABCg..."', 'Resume from cursor'),
23
+ ].join('\n')}`)
24
+ .action(async (handle, cmdOpts) => {
25
+ const opts = program.opts();
26
+ const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
27
+ const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
28
+ const count = Number.parseInt(cmdOpts.count || '20', 10);
29
+ const maxPagesParsed = parsePositiveIntFlag(cmdOpts.maxPages, '--max-pages');
30
+ if (!maxPagesParsed.ok) {
31
+ console.error(`${ctx.p('err')}${maxPagesParsed.error}`);
32
+ process.exit(2);
33
+ }
34
+ const maxPages = maxPagesParsed.value;
35
+ const delayParsed = parseNonNegativeIntFlag(cmdOpts.delay, '--delay', 1000);
36
+ if (!delayParsed.ok) {
37
+ console.error(`${ctx.p('err')}${delayParsed.error}`);
38
+ process.exit(2);
39
+ }
40
+ const pageDelayMs = delayParsed.value;
41
+ // Validate inputs
42
+ if (!Number.isFinite(count) || count <= 0) {
43
+ console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
44
+ process.exit(2);
45
+ }
46
+ const pageSize = 20;
47
+ const hardMaxPages = 10;
48
+ const hardMaxTweets = pageSize * hardMaxPages;
49
+ if (count > hardMaxTweets) {
50
+ console.error(`${ctx.p('err')}Invalid --count. Max ${hardMaxTweets} tweets per run (safety cap: ${hardMaxPages} pages). Use --cursor to continue.`);
51
+ process.exit(2);
52
+ }
53
+ if (maxPages !== undefined && maxPages > hardMaxPages) {
54
+ console.error(`${ctx.p('err')}Invalid --max-pages. Expected a positive integer (max: ${hardMaxPages}).`);
55
+ process.exit(2);
56
+ }
57
+ // Normalize handle (strip @ if present)
58
+ const username = normalizeHandle(handle);
59
+ if (!username) {
60
+ console.error(`${ctx.p('err')}Invalid handle: ${handle}`);
61
+ process.exit(2);
62
+ }
63
+ const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
64
+ for (const warning of warnings) {
65
+ console.error(`${ctx.p('warn')}${warning}`);
66
+ }
67
+ if (!cookies.authToken || !cookies.ct0) {
68
+ console.error(`${ctx.p('err')}Missing required credentials`);
69
+ process.exit(1);
70
+ }
71
+ const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
72
+ // Look up user ID from username
73
+ console.error(`${ctx.p('info')}Looking up @${username}...`);
74
+ const userLookup = await client.getUserIdByUsername(username);
75
+ if (!userLookup.success || !userLookup.userId) {
76
+ console.error(`${ctx.p('err')}${userLookup.error || `Could not find user @${username}`}`);
77
+ process.exit(1);
78
+ }
79
+ const displayName = userLookup.name
80
+ ? `${userLookup.name} (@${userLookup.username})`
81
+ : `@${userLookup.username}`;
82
+ console.error(`${ctx.p('info')}Fetching tweets from ${displayName}...`);
83
+ const includeRaw = cmdOpts.jsonFull ?? false;
84
+ const wantsPaginationOutput = Boolean(cmdOpts.cursor) || maxPages !== undefined || count > pageSize;
85
+ const result = await client.getUserTweetsPaged(userLookup.userId, count, {
86
+ includeRaw,
87
+ maxPages,
88
+ cursor: cmdOpts.cursor,
89
+ pageDelayMs,
90
+ });
91
+ if (result.success) {
92
+ const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
93
+ ctx.printTweetsResult(result, {
94
+ json: isJson,
95
+ usePagination: wantsPaginationOutput,
96
+ emptyMessage: `No tweets found for @${username}.`,
97
+ });
98
+ // Show pagination hint if there's more
99
+ if (result.nextCursor && !cmdOpts.json && !cmdOpts.jsonFull) {
100
+ console.error(`${ctx.p('info')}More tweets available. Use --cursor "${result.nextCursor}" to continue.`);
101
+ }
102
+ }
103
+ else {
104
+ console.error(`${ctx.p('err')}Failed to fetch tweets: ${result.error}`);
105
+ process.exit(1);
106
+ }
107
+ });
108
+ }
109
+ //# sourceMappingURL=user-tweets.js.map
@@ -0,0 +1,4 @@
1
+ import type { Command } from 'commander';
2
+ import type { CliContext } from '../cli/shared.js';
3
+ export declare function registerUserCommands(program: Command, ctx: CliContext): void;
4
+ //# sourceMappingURL=users.d.ts.map
@@ -0,0 +1,295 @@
1
+ import { normalizeHandle } from '../lib/normalize-handle.js';
2
+ import { TwitterClient } from '../lib/twitter-client.js';
3
+ function formatAboutProfile(profile, ctx, handle) {
4
+ const lines = [`${ctx.p('info')}Account information for @${handle}:`];
5
+ if (profile.accountBasedIn) {
6
+ lines.push(` Account based in: ${profile.accountBasedIn}`);
7
+ }
8
+ if (profile.createdCountryAccurate !== undefined) {
9
+ lines.push(` Creation country accurate: ${profile.createdCountryAccurate ? 'Yes' : 'No'}`);
10
+ }
11
+ if (profile.locationAccurate !== undefined) {
12
+ lines.push(` Location accurate: ${profile.locationAccurate ? 'Yes' : 'No'}`);
13
+ }
14
+ if (profile.source) {
15
+ lines.push(`${ctx.l('source')}${profile.source}`);
16
+ }
17
+ if (profile.learnMoreUrl) {
18
+ lines.push(` Learn more: ${profile.learnMoreUrl}`);
19
+ }
20
+ return lines;
21
+ }
22
+ function printUsers(users, ctx) {
23
+ for (const user of users) {
24
+ console.log(`@${user.username} (${user.name})`);
25
+ if (user.description) {
26
+ console.log(` ${user.description.slice(0, 100)}${user.description.length > 100 ? '...' : ''}`);
27
+ }
28
+ if (user.followersCount !== undefined) {
29
+ console.log(` ${ctx.p('info')}${user.followersCount.toLocaleString()} followers`);
30
+ }
31
+ console.log('──────────────────────────────────────────────────');
32
+ }
33
+ }
34
+ async function resolveUserIdOrExit(client, requestedUserId, ctx) {
35
+ if (requestedUserId) {
36
+ return requestedUserId;
37
+ }
38
+ const currentUser = await client.getCurrentUser();
39
+ if (!currentUser.success || !currentUser.user?.id) {
40
+ console.error(`${ctx.p('err')}Failed to get current user: ${currentUser.error || 'Unknown error'}`);
41
+ process.exit(1);
42
+ }
43
+ return currentUser.user.id;
44
+ }
45
+ async function runUserListCommand(program, ctx, spec, cmdOpts) {
46
+ const opts = program.opts();
47
+ const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
48
+ const count = Number.parseInt(cmdOpts.count || '20', 10);
49
+ const maxPages = cmdOpts.maxPages ? Number.parseInt(cmdOpts.maxPages, 10) : undefined;
50
+ const usePagination = cmdOpts.all || cmdOpts.cursor;
51
+ if (maxPages !== undefined && !cmdOpts.all) {
52
+ console.error(`${ctx.p('err')}--max-pages requires --all.`);
53
+ process.exit(1);
54
+ }
55
+ if (maxPages !== undefined && (!Number.isFinite(maxPages) || maxPages <= 0)) {
56
+ console.error(`${ctx.p('err')}Invalid --max-pages. Expected a positive integer.`);
57
+ process.exit(1);
58
+ }
59
+ const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
60
+ for (const warning of warnings) {
61
+ console.error(`${ctx.p('warn')}${warning}`);
62
+ }
63
+ if (!cookies.authToken || !cookies.ct0) {
64
+ console.error(`${ctx.p('err')}Missing required credentials`);
65
+ process.exit(1);
66
+ }
67
+ const client = new TwitterClient({ cookies, timeoutMs });
68
+ const userId = await resolveUserIdOrExit(client, cmdOpts.user, ctx);
69
+ if (cmdOpts.all) {
70
+ const allUsers = [];
71
+ const seen = new Set();
72
+ let cursor = cmdOpts.cursor;
73
+ let pageNum = 0;
74
+ let nextCursor;
75
+ while (true) {
76
+ pageNum += 1;
77
+ if (!cmdOpts.json) {
78
+ console.error(`${ctx.p('info')}Fetching page ${pageNum}...`);
79
+ }
80
+ const result = await spec.fetch(client, userId, count, cursor);
81
+ if (!result.success || !result.users) {
82
+ console.error(`${ctx.p('err')}Failed to fetch ${spec.name}: ${result.error}`);
83
+ process.exit(1);
84
+ }
85
+ let added = 0;
86
+ for (const user of result.users) {
87
+ if (!seen.has(user.id)) {
88
+ seen.add(user.id);
89
+ allUsers.push(user);
90
+ added += 1;
91
+ }
92
+ }
93
+ const pageCursor = result.nextCursor;
94
+ if (!pageCursor || result.users.length === 0 || added === 0 || pageCursor === cursor) {
95
+ nextCursor = undefined;
96
+ break;
97
+ }
98
+ if (maxPages && pageNum >= maxPages) {
99
+ nextCursor = pageCursor;
100
+ break;
101
+ }
102
+ cursor = pageCursor;
103
+ await new Promise((resolve) => setTimeout(resolve, 1000));
104
+ }
105
+ if (cmdOpts.json) {
106
+ console.log(JSON.stringify({ users: allUsers, nextCursor: nextCursor ?? null }, null, 2));
107
+ }
108
+ else {
109
+ console.error(`${ctx.p('info')}Total: ${allUsers.length} users`);
110
+ if (nextCursor) {
111
+ console.error(`${ctx.p('info')}Stopped at --max-pages. Use --cursor to continue.`);
112
+ console.error(`${ctx.p('info')}Next cursor: ${nextCursor}`);
113
+ }
114
+ printUsers(allUsers, ctx);
115
+ }
116
+ return;
117
+ }
118
+ const result = await spec.fetch(client, userId, count, cmdOpts.cursor);
119
+ if (result.success && result.users) {
120
+ if (cmdOpts.json) {
121
+ if (usePagination) {
122
+ console.log(JSON.stringify({ users: result.users, nextCursor: result.nextCursor ?? null }, null, 2));
123
+ }
124
+ else {
125
+ console.log(JSON.stringify(result.users, null, 2));
126
+ }
127
+ }
128
+ else {
129
+ if (result.users.length === 0) {
130
+ console.log('No users found.');
131
+ }
132
+ else {
133
+ printUsers(result.users, ctx);
134
+ if (result.nextCursor) {
135
+ console.error(`${ctx.p('info')}Next cursor: ${result.nextCursor}`);
136
+ }
137
+ }
138
+ }
139
+ }
140
+ else {
141
+ console.error(`${ctx.p('err')}Failed to fetch ${spec.name}: ${result.error}`);
142
+ process.exit(1);
143
+ }
144
+ }
145
+ export function registerUserCommands(program, ctx) {
146
+ const registerUserListCommand = (spec) => {
147
+ program
148
+ .command(spec.name)
149
+ .description(spec.description)
150
+ .option('--user <userId>', `User ID to get ${spec.name} for (defaults to current user)`)
151
+ .option('-n, --count <number>', 'Number of users to fetch per page', '20')
152
+ .option('--cursor <cursor>', 'Cursor for pagination (from previous response)')
153
+ .option('--all', 'Fetch all users (paginate automatically)')
154
+ .option('--max-pages <number>', 'Stop after N pages when using --all')
155
+ .option('--json', 'Output as JSON')
156
+ .action(async (cmdOpts) => runUserListCommand(program, ctx, spec, cmdOpts));
157
+ };
158
+ registerUserListCommand({
159
+ name: 'following',
160
+ description: 'Get users that you (or another user) follow',
161
+ fetch: (client, userId, count, cursor) => client.getFollowing(userId, count, cursor),
162
+ });
163
+ registerUserListCommand({
164
+ name: 'followers',
165
+ description: 'Get users that follow you (or another user)',
166
+ fetch: (client, userId, count, cursor) => client.getFollowers(userId, count, cursor),
167
+ });
168
+ program
169
+ .command('likes')
170
+ .description('Get your liked tweets')
171
+ .option('-n, --count <number>', 'Number of likes to fetch', '20')
172
+ .option('--all', 'Fetch all likes (paged)')
173
+ .option('--max-pages <number>', 'Stop after N pages when using --all')
174
+ .option('--cursor <string>', 'Resume pagination from a cursor')
175
+ .option('--json', 'Output as JSON')
176
+ .option('--json-full', 'Output as JSON with full raw API response in _raw field')
177
+ .action(async (cmdOpts) => {
178
+ const opts = program.opts();
179
+ const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
180
+ const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
181
+ const count = Number.parseInt(cmdOpts.count || '20', 10);
182
+ const maxPages = cmdOpts.maxPages ? Number.parseInt(cmdOpts.maxPages, 10) : undefined;
183
+ const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
184
+ for (const warning of warnings) {
185
+ console.error(`${ctx.p('warn')}${warning}`);
186
+ }
187
+ if (!cookies.authToken || !cookies.ct0) {
188
+ console.error(`${ctx.p('err')}Missing required credentials`);
189
+ process.exit(1);
190
+ }
191
+ const usePagination = cmdOpts.all || cmdOpts.cursor;
192
+ if (maxPages !== undefined && !usePagination) {
193
+ console.error(`${ctx.p('err')}--max-pages requires --all or --cursor.`);
194
+ process.exit(1);
195
+ }
196
+ if (!usePagination && (!Number.isFinite(count) || count <= 0)) {
197
+ console.error(`${ctx.p('err')}Invalid --count. Expected a positive integer.`);
198
+ process.exit(1);
199
+ }
200
+ if (maxPages !== undefined && (!Number.isFinite(maxPages) || maxPages <= 0)) {
201
+ console.error(`${ctx.p('err')}Invalid --max-pages. Expected a positive integer.`);
202
+ process.exit(1);
203
+ }
204
+ const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
205
+ const includeRaw = cmdOpts.jsonFull ?? false;
206
+ const timelineOptions = { includeRaw };
207
+ const paginationOptions = { includeRaw, maxPages, cursor: cmdOpts.cursor };
208
+ const result = usePagination
209
+ ? await client.getAllLikes(paginationOptions)
210
+ : await client.getLikes(count, timelineOptions);
211
+ if (result.success) {
212
+ const isJson = Boolean(cmdOpts.json || cmdOpts.jsonFull);
213
+ ctx.printTweetsResult(result, {
214
+ json: isJson,
215
+ usePagination: Boolean(usePagination),
216
+ emptyMessage: 'No liked tweets found.',
217
+ });
218
+ }
219
+ else {
220
+ console.error(`${ctx.p('err')}Failed to fetch likes: ${result.error}`);
221
+ process.exit(1);
222
+ }
223
+ });
224
+ program
225
+ .command('whoami')
226
+ .description('Show which Twitter account the current credentials belong to')
227
+ .action(async () => {
228
+ const opts = program.opts();
229
+ const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
230
+ const quoteDepth = ctx.resolveQuoteDepthFromOptions(opts);
231
+ const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
232
+ for (const warning of warnings) {
233
+ console.error(`${ctx.p('warn')}${warning}`);
234
+ }
235
+ if (!cookies.authToken || !cookies.ct0) {
236
+ console.error(`${ctx.p('err')}Missing required credentials`);
237
+ process.exit(1);
238
+ }
239
+ if (cookies.source) {
240
+ console.error(`${ctx.l('source')}${cookies.source}`);
241
+ }
242
+ const client = new TwitterClient({ cookies, timeoutMs, quoteDepth });
243
+ const result = await client.getCurrentUser();
244
+ const credentialSource = cookies.source ?? 'env/auto-detected cookies';
245
+ if (result.success && result.user) {
246
+ console.log(`${ctx.l('user')}@${result.user.username} (${result.user.name})`);
247
+ console.log(`${ctx.l('userId')}${result.user.id}`);
248
+ console.log(`${ctx.l('engine')}graphql`);
249
+ console.log(`${ctx.l('credentials')}${credentialSource}`);
250
+ }
251
+ else {
252
+ console.error(`${ctx.p('err')}Failed to determine current user: ${result.error ?? 'Unknown error'}`);
253
+ process.exit(1);
254
+ }
255
+ });
256
+ program
257
+ .command('about')
258
+ .description('Get account origin and location information for a user')
259
+ .argument('<username>', 'Twitter username (with or without @)')
260
+ .option('--json', 'Output as JSON')
261
+ .action(async (username, cmdOpts) => {
262
+ const opts = program.opts();
263
+ const timeoutMs = ctx.resolveTimeoutFromOptions(opts);
264
+ const normalizedHandle = normalizeHandle(username);
265
+ if (!normalizedHandle) {
266
+ console.error(`${ctx.p('err')}Invalid username: ${username}`);
267
+ process.exit(1);
268
+ }
269
+ const { cookies, warnings } = await ctx.resolveCredentialsFromOptions(opts);
270
+ for (const warning of warnings) {
271
+ console.error(`${ctx.p('warn')}${warning}`);
272
+ }
273
+ if (!cookies.authToken || !cookies.ct0) {
274
+ console.error(`${ctx.p('err')}Missing required credentials`);
275
+ process.exit(1);
276
+ }
277
+ const client = new TwitterClient({ cookies, timeoutMs });
278
+ const result = await client.getUserAboutAccount(normalizedHandle);
279
+ if (result.success && result.aboutProfile) {
280
+ if (cmdOpts.json) {
281
+ console.log(JSON.stringify(result.aboutProfile, null, 2));
282
+ }
283
+ else {
284
+ for (const line of formatAboutProfile(result.aboutProfile, ctx, normalizedHandle)) {
285
+ console.log(line);
286
+ }
287
+ }
288
+ }
289
+ else {
290
+ console.error(`${ctx.p('err')}Failed to fetch account information: ${result.error ?? 'Unknown error'}`);
291
+ process.exit(1);
292
+ }
293
+ });
294
+ }
295
+ //# sourceMappingURL=users.js.map
@@ -0,0 +1,2 @@
1
+ export * from './lib/index.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from './lib/index.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ export type CliInvocation = {
2
+ argv: string[] | null;
3
+ showHelp: boolean;
4
+ };
5
+ export declare function looksLikeTweetInput(value: string): boolean;
6
+ export declare function resolveCliInvocation(rawArgs: string[], knownCommands: Set<string>): CliInvocation;
7
+ //# sourceMappingURL=cli-args.d.ts.map
@@ -0,0 +1,25 @@
1
+ const TWEET_URL_REGEX = /^(?:https?:\/\/)?(?:www\.)?(?:twitter\.com|x\.com)\/[^/]+\/status\/\d+/i;
2
+ const TWEET_ID_REGEX = /^\d{8,}$/;
3
+ export function looksLikeTweetInput(value) {
4
+ const trimmed = value.trim();
5
+ if (!trimmed) {
6
+ return false;
7
+ }
8
+ return TWEET_URL_REGEX.test(trimmed) || TWEET_ID_REGEX.test(trimmed);
9
+ }
10
+ export function resolveCliInvocation(rawArgs, knownCommands) {
11
+ if (rawArgs.length === 0) {
12
+ return { argv: null, showHelp: true };
13
+ }
14
+ const hasKnownCommand = rawArgs.some((arg) => knownCommands.has(arg));
15
+ if (!hasKnownCommand) {
16
+ const tweetArgIndex = rawArgs.findIndex(looksLikeTweetInput);
17
+ if (tweetArgIndex >= 0) {
18
+ const rewrittenArgs = [...rawArgs];
19
+ rewrittenArgs.splice(tweetArgIndex, 0, 'read');
20
+ return { argv: ['node', 'bird', ...rewrittenArgs], showHelp: false };
21
+ }
22
+ }
23
+ return { argv: null, showHelp: false };
24
+ }
25
+ //# sourceMappingURL=cli-args.js.map
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Browser cookie extraction for Twitter authentication.
3
+ * Delegates to @steipete/sweet-cookie for Safari/Chrome/Firefox reads.
4
+ */
5
+ export interface TwitterCookies {
6
+ authToken: string | null;
7
+ ct0: string | null;
8
+ cookieHeader: string | null;
9
+ source: string | null;
10
+ }
11
+ export interface CookieExtractionResult {
12
+ cookies: TwitterCookies;
13
+ warnings: string[];
14
+ }
15
+ export type CookieSource = 'safari' | 'chrome' | 'firefox';
16
+ export declare function extractCookiesFromSafari(): Promise<CookieExtractionResult>;
17
+ export declare function extractCookiesFromChrome(profile?: string): Promise<CookieExtractionResult>;
18
+ export declare function extractCookiesFromFirefox(profile?: string): Promise<CookieExtractionResult>;
19
+ /**
20
+ * Resolve Twitter credentials from multiple sources.
21
+ * Priority: CLI args > environment variables > browsers (ordered).
22
+ */
23
+ export declare function resolveCredentials(options: {
24
+ authToken?: string;
25
+ ct0?: string;
26
+ cookieSource?: CookieSource | CookieSource[];
27
+ chromeProfile?: string;
28
+ firefoxProfile?: string;
29
+ cookieTimeoutMs?: number;
30
+ }): Promise<CookieExtractionResult>;
31
+ //# sourceMappingURL=cookies.d.ts.map
@@ -0,0 +1,81 @@
1
+ /**
2
+ * ── 本文件是我们替换掉的,不是上游原版 ──────────────────────────────────────
3
+ *
4
+ * 上游的 cookies.js 靠 `@steipete/sweet-cookie` 去读**本机浏览器**(Safari/Chrome/
5
+ * Firefox)里的 x.com cookie。我们把整条路砍了,换成会抛错的桩。
6
+ *
7
+ * 两个理由,第二个才是主要的:
8
+ *
9
+ * 1. 用不上。dp-worker 的凭据只有一个来源:center 同步下来的 session 文件
10
+ * (见 src/bird/credentials.ts)。TwitterClient 是显式接收 cookies 参数构造的,
11
+ * 从来不会走到这里 —— 这个模块只是被 lib/index.js 顺带 re-export 出去,却在
12
+ * import 时就把依赖拖了进来。
13
+ *
14
+ * 2. **不该有这个能力。** 一个跑在生产机上的进程,不应该具备"去翻这台机器上任意
15
+ * 浏览器配置里的登录态"这种本事。哪怕现在没人调用它,它也是一条随时可能被误用的
16
+ * 路径,而且这类代码一旦出事就是最难解释的那种。删掉它比信任它不被调用可靠。
17
+ *
18
+ * 顺带的好处:少一个 npm 依赖。这正是把 bird 内置进仓库(vendor/)的意义 ——
19
+ * 我们可以对它做这种裁剪,而不是只能整包接受。
20
+ */
21
+
22
+ const DISABLED =
23
+ "bird 的浏览器 cookie 读取在本项目里被移除了。凭据只来自 center 同步的 session 文件 —— " +
24
+ "见 dp-worker/src/bird/credentials.ts 和 vendor/bird/README.md。";
25
+
26
+ function refuse() {
27
+ throw new Error(DISABLED);
28
+ }
29
+
30
+ export async function extractCookiesFromSafari() {
31
+ return refuse();
32
+ }
33
+
34
+ export async function extractCookiesFromChrome(_profile) {
35
+ return refuse();
36
+ }
37
+
38
+ export async function extractCookiesFromFirefox(_profile) {
39
+ return refuse();
40
+ }
41
+
42
+ /**
43
+ * 只保留「显式传入 / 环境变量」这两条来源,浏览器那条直接不存在。
44
+ *
45
+ * 保留函数本身是为了让 lib/index.js 的 re-export 不断 —— 上游 CLI 代码路径我们不跑,
46
+ * 但模块形状要保持一致,否则任何一次 import 都会炸。
47
+ */
48
+ export async function resolveCredentials(options = {}) {
49
+ const cookies = { authToken: undefined, ct0: undefined, cookieHeader: undefined, source: undefined };
50
+ const warnings = [];
51
+
52
+ if (options.authToken) {
53
+ cookies.authToken = options.authToken;
54
+ cookies.source = "explicit";
55
+ }
56
+ if (options.ct0) {
57
+ cookies.ct0 = options.ct0;
58
+ cookies.source ??= "explicit";
59
+ }
60
+ for (const [names, key] of [
61
+ [["AUTH_TOKEN", "TWITTER_AUTH_TOKEN"], "authToken"],
62
+ [["CT0", "TWITTER_CT0"], "ct0"],
63
+ ]) {
64
+ if (cookies[key]) continue;
65
+ for (const n of names) {
66
+ const v = process.env[n];
67
+ if (typeof v === "string" && v.trim()) {
68
+ cookies[key] = v.trim();
69
+ cookies.source ??= `env:${n}`;
70
+ break;
71
+ }
72
+ }
73
+ }
74
+
75
+ if (cookies.authToken && cookies.ct0) {
76
+ cookies.cookieHeader = `auth_token=${cookies.authToken}; ct0=${cookies.ct0}`;
77
+ } else {
78
+ warnings.push(DISABLED);
79
+ }
80
+ return { cookies, warnings };
81
+ }
@@ -0,0 +1,2 @@
1
+ export declare function extractBookmarkFolderId(input: string): string | null;
2
+ //# sourceMappingURL=extract-bookmark-folder-id.d.ts.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Extract bookmark folder (collection) ID from an X/Twitter bookmarks URL.
3
+ */
4
+ const BOOKMARK_FOLDER_URL_REGEX = /(?:twitter\.com|x\.com)\/i\/bookmarks\/(\d+)/i;
5
+ const BOOKMARK_FOLDER_ID_REGEX = /^\d{5,}$/;
6
+ export function extractBookmarkFolderId(input) {
7
+ const trimmed = input.trim();
8
+ if (!trimmed) {
9
+ return null;
10
+ }
11
+ const urlMatch = BOOKMARK_FOLDER_URL_REGEX.exec(trimmed);
12
+ if (urlMatch) {
13
+ return urlMatch[1];
14
+ }
15
+ if (BOOKMARK_FOLDER_ID_REGEX.test(trimmed)) {
16
+ return trimmed;
17
+ }
18
+ return null;
19
+ }
20
+ //# sourceMappingURL=extract-bookmark-folder-id.js.map
@@ -0,0 +1,2 @@
1
+ export declare function extractListId(input: string): string | null;
2
+ //# sourceMappingURL=extract-list-id.d.ts.map
@@ -0,0 +1,19 @@
1
+ // ABOUTME: Extract list ID from an X/Twitter list URL.
2
+ // ABOUTME: Returns list ID or null if input is invalid.
3
+ const LIST_URL_REGEX = /(?:twitter\.com|x\.com)\/i\/lists\/(\d+)/i;
4
+ const LIST_ID_REGEX = /^\d{5,}$/;
5
+ export function extractListId(input) {
6
+ const trimmed = input.trim();
7
+ if (!trimmed) {
8
+ return null;
9
+ }
10
+ const urlMatch = LIST_URL_REGEX.exec(trimmed);
11
+ if (urlMatch) {
12
+ return urlMatch[1];
13
+ }
14
+ if (LIST_ID_REGEX.test(trimmed)) {
15
+ return trimmed;
16
+ }
17
+ return null;
18
+ }
19
+ //# sourceMappingURL=extract-list-id.js.map
@@ -0,0 +1,2 @@
1
+ export declare function extractTweetId(input: string): string;
2
+ //# sourceMappingURL=extract-tweet-id.d.ts.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Extract tweet ID from a Twitter/X URL or return the input unchanged if it's already an ID.
3
+ */
4
+ const TWEET_URL_REGEX = /(?:twitter\.com|x\.com)\/(?:\w+\/status|i\/web\/status)\/(\d+)/i;
5
+ export function extractTweetId(input) {
6
+ // If it's a URL, extract the tweet ID
7
+ const urlMatch = TWEET_URL_REGEX.exec(input);
8
+ if (urlMatch) {
9
+ return urlMatch[1];
10
+ }
11
+ // Assume it's already an ID
12
+ return input;
13
+ }
14
+ //# sourceMappingURL=extract-tweet-id.js.map
@@ -0,0 +1,17 @@
1
+ {
2
+ "global": {
3
+ "responsive_web_grok_annotations_enabled": false,
4
+ "post_ctas_fetch_enabled": true,
5
+ "responsive_web_graphql_exclude_directive_enabled": true
6
+ },
7
+ "sets": {
8
+ "lists": {
9
+ "blue_business_profile_image_shape_enabled": true,
10
+ "tweetypie_unmention_optimization_enabled": true,
11
+ "responsive_web_text_conversations_enabled": false,
12
+ "interactive_text_enabled": true,
13
+ "vibe_api_enabled": true,
14
+ "responsive_web_twitter_blue_verified_badge_is_enabled": true
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,10 @@
1
+ export { type CookieExtractionResult, type CookieSource, extractCookiesFromChrome, extractCookiesFromFirefox, extractCookiesFromSafari, resolveCredentials, type TwitterCookies, } from './cookies.js';
2
+ export { runtimeQueryIds } from './runtime-query-ids.js';
3
+ export { type CurrentUserResult, type FollowingResult, type GetTweetResult, type SearchResult, type TweetData, TwitterClient, type TwitterClientOptions, type TwitterUser, } from './twitter-client.js';
4
+ export type { HomeTimelineFetchOptions } from './twitter-client-home.js';
5
+ export type { ExploreTab, NewsFetchOptions, NewsItem, NewsResult } from './twitter-client-news.js';
6
+ export type { SearchFetchOptions } from './twitter-client-search.js';
7
+ export type { TimelineFetchOptions } from './twitter-client-timelines.js';
8
+ export type { TweetFetchOptions } from './twitter-client-tweet-detail.js';
9
+ export type { AboutAccountProfile, AboutAccountResult, TweetResult, UploadMediaResult, } from './twitter-client-types.js';
10
+ //# sourceMappingURL=index.d.ts.map