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,113 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { registerBookmarksCommand } from '../commands/bookmarks.js';
|
|
3
|
+
import { registerCheckCommand } from '../commands/check.js';
|
|
4
|
+
import { registerFollowCommands } from '../commands/follow.js';
|
|
5
|
+
import { registerHelpCommand } from '../commands/help.js';
|
|
6
|
+
import { registerHomeCommand } from '../commands/home.js';
|
|
7
|
+
import { registerListsCommand } from '../commands/lists.js';
|
|
8
|
+
import { registerNewsCommand } from '../commands/news.js';
|
|
9
|
+
import { registerPostCommands } from '../commands/post.js';
|
|
10
|
+
import { registerQueryIdsCommand } from '../commands/query-ids.js';
|
|
11
|
+
import { registerReadCommands } from '../commands/read.js';
|
|
12
|
+
import { registerSearchCommands } from '../commands/search.js';
|
|
13
|
+
import { registerUnbookmarkCommand } from '../commands/unbookmark.js';
|
|
14
|
+
import { registerUserTweetsCommand } from '../commands/user-tweets.js';
|
|
15
|
+
import { registerUserCommands } from '../commands/users.js';
|
|
16
|
+
import { getCliVersion } from '../lib/version.js';
|
|
17
|
+
import { collectCookieSource } from './shared.js';
|
|
18
|
+
export const KNOWN_COMMANDS = new Set([
|
|
19
|
+
'tweet',
|
|
20
|
+
'reply',
|
|
21
|
+
'query-ids',
|
|
22
|
+
'read',
|
|
23
|
+
'replies',
|
|
24
|
+
'thread',
|
|
25
|
+
'search',
|
|
26
|
+
'mentions',
|
|
27
|
+
'bookmarks',
|
|
28
|
+
'unbookmark',
|
|
29
|
+
'follow',
|
|
30
|
+
'unfollow',
|
|
31
|
+
'following',
|
|
32
|
+
'followers',
|
|
33
|
+
'likes',
|
|
34
|
+
'lists',
|
|
35
|
+
'list-timeline',
|
|
36
|
+
'home',
|
|
37
|
+
'user-tweets',
|
|
38
|
+
'news',
|
|
39
|
+
'trending',
|
|
40
|
+
'help',
|
|
41
|
+
'whoami',
|
|
42
|
+
'check',
|
|
43
|
+
]);
|
|
44
|
+
export function createProgram(ctx) {
|
|
45
|
+
const program = new Command();
|
|
46
|
+
program.configureHelp({
|
|
47
|
+
showGlobalOptions: true,
|
|
48
|
+
styleTitle: (t) => ctx.colors.section(t),
|
|
49
|
+
styleUsage: (t) => ctx.colors.description(t),
|
|
50
|
+
styleCommandText: (t) => ctx.colors.command(t),
|
|
51
|
+
styleCommandDescription: (t) => ctx.colors.muted(t),
|
|
52
|
+
styleOptionTerm: (t) => ctx.colors.option(t),
|
|
53
|
+
styleOptionText: (t) => ctx.colors.option(t),
|
|
54
|
+
styleOptionDescription: (t) => ctx.colors.muted(t),
|
|
55
|
+
styleArgumentTerm: (t) => ctx.colors.argument(t),
|
|
56
|
+
styleArgumentText: (t) => ctx.colors.argument(t),
|
|
57
|
+
styleArgumentDescription: (t) => ctx.colors.muted(t),
|
|
58
|
+
styleSubcommandTerm: (t) => ctx.colors.command(t),
|
|
59
|
+
styleSubcommandText: (t) => ctx.colors.command(t),
|
|
60
|
+
styleSubcommandDescription: (t) => ctx.colors.muted(t),
|
|
61
|
+
styleDescriptionText: (t) => ctx.colors.muted(t),
|
|
62
|
+
});
|
|
63
|
+
const collect = (value, previous = []) => {
|
|
64
|
+
previous.push(value);
|
|
65
|
+
return previous;
|
|
66
|
+
};
|
|
67
|
+
program.addHelpText('beforeAll', () => `${ctx.colors.banner('bird')} ${ctx.colors.muted(getCliVersion())} ${ctx.colors.subtitle('— fast X CLI for tweeting, replying, and reading')}`);
|
|
68
|
+
program.name('bird').description('Post tweets and replies via Twitter/X GraphQL API').version(getCliVersion());
|
|
69
|
+
const formatExample = (command, description) => `${ctx.colors.command(` ${command}`)}\n${ctx.colors.muted(` ${description}`)}`;
|
|
70
|
+
program.addHelpText('afterAll', () => `\n${ctx.colors.section('Examples')}\n${[
|
|
71
|
+
formatExample('bird whoami', 'Show the logged-in account via GraphQL cookies'),
|
|
72
|
+
formatExample('bird --firefox-profile default-release whoami', 'Use Firefox profile cookies'),
|
|
73
|
+
formatExample('bird tweet "hello from bird"', 'Send a tweet'),
|
|
74
|
+
formatExample('bird 1234567890123456789 --json', 'Read a tweet (ID or URL shorthand for `read`) and print JSON'),
|
|
75
|
+
].join('\n\n')}\n\n${ctx.colors.section('Shortcuts')}\n${[
|
|
76
|
+
formatExample('bird <tweet-id-or-url> [--json]', 'Shorthand for `bird read <tweet-id-or-url>`'),
|
|
77
|
+
].join('\n\n')}\n\n${ctx.colors.section('JSON Output')}\n${ctx.colors.muted(` Add ${ctx.colors.option('--json')} to: read, replies, thread, search, mentions, bookmarks, likes, following, followers, about, lists, list-timeline, user-tweets, query-ids`)}\n${ctx.colors.muted(` Add ${ctx.colors.option('--json-full')} to include raw API response in ${ctx.colors.argument('_raw')} field (tweet commands only)`)}\n${ctx.colors.muted(` (Run ${ctx.colors.command('bird <command> --help')} to see per-command flags.)`)}`);
|
|
78
|
+
program.addHelpText('afterAll', () => `\n\n${ctx.colors.section('Config')}\n${ctx.colors.muted(` Reads ${ctx.colors.argument('~/.config/bird/config.json5')} and ${ctx.colors.argument('./.birdrc.json5')} (JSON5)`)}\n${ctx.colors.muted(` Supports: chromeProfile, chromeProfileDir, firefoxProfile, cookieSource, cookieTimeoutMs, timeoutMs, quoteDepth`)}\n\n${ctx.colors.section('Env')}\n${ctx.colors.muted(` ${ctx.colors.option('NO_COLOR')}, ${ctx.colors.option('BIRD_TIMEOUT_MS')}, ${ctx.colors.option('BIRD_COOKIE_TIMEOUT_MS')}, ${ctx.colors.option('BIRD_QUOTE_DEPTH')}`)}`);
|
|
79
|
+
program
|
|
80
|
+
.option('--auth-token <token>', 'Twitter auth_token cookie')
|
|
81
|
+
.option('--ct0 <token>', 'Twitter ct0 cookie')
|
|
82
|
+
.option('--chrome-profile <name>', 'Chrome profile name for cookie extraction', ctx.config.chromeProfile)
|
|
83
|
+
.option('--chrome-profile-dir <path>', 'Chrome/Chromium profile directory or cookie DB path for cookie extraction', ctx.config.chromeProfileDir)
|
|
84
|
+
.option('--firefox-profile <name>', 'Firefox profile name for cookie extraction', ctx.config.firefoxProfile)
|
|
85
|
+
.option('--cookie-timeout <ms>', 'Cookie extraction timeout in milliseconds (keychain/OS helpers)')
|
|
86
|
+
.option('--cookie-source <source>', 'Cookie source for browser cookie extraction (repeatable)', collectCookieSource)
|
|
87
|
+
.option('--media <path>', 'Attach media file (repeatable, up to 4 images or 1 video)', collect)
|
|
88
|
+
.option('--alt <text>', 'Alt text for the corresponding --media (repeatable)', collect)
|
|
89
|
+
.option('--timeout <ms>', 'Request timeout in milliseconds')
|
|
90
|
+
.option('--quote-depth <depth>', 'Max quoted tweet depth (default: 1; 0 disables)')
|
|
91
|
+
.option('--plain', 'Plain output (stable, no emoji, no color)')
|
|
92
|
+
.option('--no-emoji', 'Disable emoji output')
|
|
93
|
+
.option('--no-color', 'Disable ANSI colors (or set NO_COLOR)');
|
|
94
|
+
program.hook('preAction', (_thisCommand, actionCommand) => {
|
|
95
|
+
ctx.applyOutputFromCommand(actionCommand);
|
|
96
|
+
});
|
|
97
|
+
registerHelpCommand(program, ctx);
|
|
98
|
+
registerQueryIdsCommand(program, ctx);
|
|
99
|
+
registerPostCommands(program, ctx);
|
|
100
|
+
registerReadCommands(program, ctx);
|
|
101
|
+
registerSearchCommands(program, ctx);
|
|
102
|
+
registerBookmarksCommand(program, ctx);
|
|
103
|
+
registerUnbookmarkCommand(program, ctx);
|
|
104
|
+
registerFollowCommands(program, ctx);
|
|
105
|
+
registerListsCommand(program, ctx);
|
|
106
|
+
registerHomeCommand(program, ctx);
|
|
107
|
+
registerUserCommands(program, ctx);
|
|
108
|
+
registerUserTweetsCommand(program, ctx);
|
|
109
|
+
registerNewsCommand(program, ctx);
|
|
110
|
+
registerCheckCommand(program, ctx);
|
|
111
|
+
return program;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=program.js.map
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
import { type CookieSource, resolveCredentials } from '../lib/cookies.js';
|
|
3
|
+
import { labelPrefix, type OutputConfig, statusPrefix } from '../lib/output.js';
|
|
4
|
+
import type { TweetData } from '../lib/twitter-client.js';
|
|
5
|
+
export type BirdConfig = {
|
|
6
|
+
chromeProfile?: string;
|
|
7
|
+
chromeProfileDir?: string;
|
|
8
|
+
firefoxProfile?: string;
|
|
9
|
+
cookieSource?: CookieSource | CookieSource[];
|
|
10
|
+
cookieTimeoutMs?: number;
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
quoteDepth?: number;
|
|
13
|
+
};
|
|
14
|
+
export type MediaSpec = {
|
|
15
|
+
path: string;
|
|
16
|
+
alt?: string;
|
|
17
|
+
mime: string;
|
|
18
|
+
buffer: Buffer;
|
|
19
|
+
};
|
|
20
|
+
export type CliContext = {
|
|
21
|
+
isTty: boolean;
|
|
22
|
+
getOutput: () => OutputConfig;
|
|
23
|
+
colors: {
|
|
24
|
+
banner: (t: string) => string;
|
|
25
|
+
subtitle: (t: string) => string;
|
|
26
|
+
section: (t: string) => string;
|
|
27
|
+
bullet: (t: string) => string;
|
|
28
|
+
command: (t: string) => string;
|
|
29
|
+
option: (t: string) => string;
|
|
30
|
+
argument: (t: string) => string;
|
|
31
|
+
description: (t: string) => string;
|
|
32
|
+
muted: (t: string) => string;
|
|
33
|
+
accent: (t: string) => string;
|
|
34
|
+
};
|
|
35
|
+
p: (kind: Parameters<typeof statusPrefix>[0]) => string;
|
|
36
|
+
l: (kind: Parameters<typeof labelPrefix>[0]) => string;
|
|
37
|
+
config: BirdConfig;
|
|
38
|
+
applyOutputFromCommand: (command: Command) => void;
|
|
39
|
+
resolveTimeoutFromOptions: (options: {
|
|
40
|
+
timeout?: string | number;
|
|
41
|
+
}) => number | undefined;
|
|
42
|
+
resolveQuoteDepthFromOptions: (options: {
|
|
43
|
+
quoteDepth?: string | number;
|
|
44
|
+
}) => number | undefined;
|
|
45
|
+
resolveCredentialsFromOptions: (opts: CredentialsOptions) => ReturnType<typeof resolveCredentials>;
|
|
46
|
+
loadMedia: (opts: {
|
|
47
|
+
media: string[];
|
|
48
|
+
alts: string[];
|
|
49
|
+
}) => MediaSpec[];
|
|
50
|
+
printTweets: (tweets: TweetData[], opts?: {
|
|
51
|
+
json?: boolean;
|
|
52
|
+
emptyMessage?: string;
|
|
53
|
+
showSeparator?: boolean;
|
|
54
|
+
}) => void;
|
|
55
|
+
printTweetsResult: (result: {
|
|
56
|
+
tweets?: TweetData[];
|
|
57
|
+
nextCursor?: string;
|
|
58
|
+
}, opts: {
|
|
59
|
+
json: boolean;
|
|
60
|
+
usePagination: boolean;
|
|
61
|
+
emptyMessage: string;
|
|
62
|
+
}) => void;
|
|
63
|
+
extractTweetId: (tweetIdOrUrl: string) => string;
|
|
64
|
+
};
|
|
65
|
+
export declare const collectCookieSource: (value: string, previous?: CookieSource[]) => CookieSource[];
|
|
66
|
+
type CredentialsOptions = {
|
|
67
|
+
authToken?: string;
|
|
68
|
+
ct0?: string;
|
|
69
|
+
chromeProfile?: string;
|
|
70
|
+
chromeProfileDir?: string;
|
|
71
|
+
firefoxProfile?: string;
|
|
72
|
+
cookieSource?: CookieSource[];
|
|
73
|
+
cookieTimeout?: string | number;
|
|
74
|
+
};
|
|
75
|
+
export declare function createCliContext(normalizedArgs: string[], env?: NodeJS.ProcessEnv): CliContext;
|
|
76
|
+
export {};
|
|
77
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import JSON5 from 'json5';
|
|
5
|
+
import kleur from 'kleur';
|
|
6
|
+
import { resolveCredentials } from '../lib/cookies.js';
|
|
7
|
+
import { extractTweetId } from '../lib/extract-tweet-id.js';
|
|
8
|
+
import { hyperlink, labelPrefix, resolveOutputConfigFromArgv, resolveOutputConfigFromCommander, statusPrefix, } from '../lib/output.js';
|
|
9
|
+
const COOKIE_SOURCES = ['safari', 'chrome', 'firefox'];
|
|
10
|
+
function parseCookieSource(value) {
|
|
11
|
+
const normalized = value.trim().toLowerCase();
|
|
12
|
+
if (normalized === 'safari' || normalized === 'chrome' || normalized === 'firefox') {
|
|
13
|
+
return normalized;
|
|
14
|
+
}
|
|
15
|
+
throw new Error(`Invalid --cookie-source "${value}". Allowed: safari, chrome, firefox.`);
|
|
16
|
+
}
|
|
17
|
+
export const collectCookieSource = (value, previous = []) => {
|
|
18
|
+
previous.push(parseCookieSource(value));
|
|
19
|
+
return previous;
|
|
20
|
+
};
|
|
21
|
+
function resolveCookieSourceOrder(input) {
|
|
22
|
+
if (typeof input === 'string') {
|
|
23
|
+
return [parseCookieSource(input)];
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(input)) {
|
|
26
|
+
const result = [];
|
|
27
|
+
for (const entry of input) {
|
|
28
|
+
if (typeof entry !== 'string') {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
result.push(parseCookieSource(entry));
|
|
32
|
+
}
|
|
33
|
+
return result.length > 0 ? result : undefined;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
function resolveTimeoutMs(...values) {
|
|
38
|
+
for (const value of values) {
|
|
39
|
+
if (value === undefined || value === null || value === '') {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const parsed = typeof value === 'number' ? value : Number(value);
|
|
43
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
44
|
+
return parsed;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
function resolveQuoteDepth(...values) {
|
|
50
|
+
for (const value of values) {
|
|
51
|
+
if (value === undefined || value === null || value === '') {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const parsed = typeof value === 'number' ? value : Number.parseInt(value, 10);
|
|
55
|
+
if (Number.isFinite(parsed) && parsed >= 0) {
|
|
56
|
+
return Math.floor(parsed);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
function detectMime(path) {
|
|
62
|
+
const ext = path.toLowerCase();
|
|
63
|
+
if (ext.endsWith('.jpg') || ext.endsWith('.jpeg')) {
|
|
64
|
+
return 'image/jpeg';
|
|
65
|
+
}
|
|
66
|
+
if (ext.endsWith('.png')) {
|
|
67
|
+
return 'image/png';
|
|
68
|
+
}
|
|
69
|
+
if (ext.endsWith('.webp')) {
|
|
70
|
+
return 'image/webp';
|
|
71
|
+
}
|
|
72
|
+
if (ext.endsWith('.gif')) {
|
|
73
|
+
return 'image/gif';
|
|
74
|
+
}
|
|
75
|
+
if (ext.endsWith('.mp4') || ext.endsWith('.m4v')) {
|
|
76
|
+
return 'video/mp4';
|
|
77
|
+
}
|
|
78
|
+
if (ext.endsWith('.mov')) {
|
|
79
|
+
return 'video/quicktime';
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
function readConfigFile(path, warn) {
|
|
84
|
+
if (!existsSync(path)) {
|
|
85
|
+
return {};
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const raw = readFileSync(path, 'utf8');
|
|
89
|
+
const parsed = JSON5.parse(raw);
|
|
90
|
+
return parsed ?? {};
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
warn(`Failed to parse config at ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function loadConfig(warn) {
|
|
98
|
+
const globalPath = join(homedir(), '.config', 'bird', 'config.json5');
|
|
99
|
+
const localPath = join(process.cwd(), '.birdrc.json5');
|
|
100
|
+
return {
|
|
101
|
+
...readConfigFile(globalPath, warn),
|
|
102
|
+
...readConfigFile(localPath, warn),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export function createCliContext(normalizedArgs, env = process.env) {
|
|
106
|
+
const isTty = process.stdout.isTTY;
|
|
107
|
+
let output = resolveOutputConfigFromArgv(normalizedArgs, env, isTty);
|
|
108
|
+
kleur.enabled = output.color;
|
|
109
|
+
const wrap = (styler) => (text) => isTty ? styler(text) : text;
|
|
110
|
+
const colors = {
|
|
111
|
+
banner: wrap((t) => kleur.bold().blue(t)),
|
|
112
|
+
subtitle: wrap((t) => kleur.dim(t)),
|
|
113
|
+
section: wrap((t) => kleur.bold().white(t)),
|
|
114
|
+
bullet: wrap((t) => kleur.blue(t)),
|
|
115
|
+
command: wrap((t) => kleur.bold().cyan(t)),
|
|
116
|
+
option: wrap((t) => kleur.cyan(t)),
|
|
117
|
+
argument: wrap((t) => kleur.magenta(t)),
|
|
118
|
+
description: wrap((t) => kleur.white(t)),
|
|
119
|
+
muted: wrap((t) => kleur.gray(t)),
|
|
120
|
+
accent: wrap((t) => kleur.green(t)),
|
|
121
|
+
};
|
|
122
|
+
const p = (kind) => {
|
|
123
|
+
const prefix = statusPrefix(kind, output);
|
|
124
|
+
if (output.plain || !output.color) {
|
|
125
|
+
return prefix;
|
|
126
|
+
}
|
|
127
|
+
if (kind === 'ok') {
|
|
128
|
+
return kleur.green(prefix);
|
|
129
|
+
}
|
|
130
|
+
if (kind === 'warn') {
|
|
131
|
+
return kleur.yellow(prefix);
|
|
132
|
+
}
|
|
133
|
+
if (kind === 'err') {
|
|
134
|
+
return kleur.red(prefix);
|
|
135
|
+
}
|
|
136
|
+
if (kind === 'info') {
|
|
137
|
+
return kleur.cyan(prefix);
|
|
138
|
+
}
|
|
139
|
+
return kleur.gray(prefix);
|
|
140
|
+
};
|
|
141
|
+
const l = (kind) => {
|
|
142
|
+
const prefix = labelPrefix(kind, output);
|
|
143
|
+
if (output.plain || !output.color) {
|
|
144
|
+
return prefix;
|
|
145
|
+
}
|
|
146
|
+
if (kind === 'url') {
|
|
147
|
+
return kleur.cyan(prefix);
|
|
148
|
+
}
|
|
149
|
+
if (kind === 'date') {
|
|
150
|
+
return kleur.magenta(prefix);
|
|
151
|
+
}
|
|
152
|
+
if (kind === 'source') {
|
|
153
|
+
return kleur.gray(prefix);
|
|
154
|
+
}
|
|
155
|
+
if (kind === 'engine') {
|
|
156
|
+
return kleur.blue(prefix);
|
|
157
|
+
}
|
|
158
|
+
if (kind === 'credentials') {
|
|
159
|
+
return kleur.yellow(prefix);
|
|
160
|
+
}
|
|
161
|
+
if (kind === 'user') {
|
|
162
|
+
return kleur.cyan(prefix);
|
|
163
|
+
}
|
|
164
|
+
if (kind === 'userId') {
|
|
165
|
+
return kleur.magenta(prefix);
|
|
166
|
+
}
|
|
167
|
+
if (kind === 'email') {
|
|
168
|
+
return kleur.green(prefix);
|
|
169
|
+
}
|
|
170
|
+
return kleur.gray(prefix);
|
|
171
|
+
};
|
|
172
|
+
const config = loadConfig((message) => {
|
|
173
|
+
console.error(colors.muted(`${p('warn')}${message}`));
|
|
174
|
+
});
|
|
175
|
+
function applyOutputFromCommand(command) {
|
|
176
|
+
const opts = command.optsWithGlobals();
|
|
177
|
+
output = resolveOutputConfigFromCommander(opts, env, isTty);
|
|
178
|
+
kleur.enabled = output.color;
|
|
179
|
+
}
|
|
180
|
+
function resolveTimeoutFromOptions(options) {
|
|
181
|
+
return resolveTimeoutMs(options.timeout, config.timeoutMs, env.BIRD_TIMEOUT_MS);
|
|
182
|
+
}
|
|
183
|
+
function resolveCookieTimeoutFromOptions(options) {
|
|
184
|
+
return resolveTimeoutMs(options.cookieTimeout, config.cookieTimeoutMs, env.BIRD_COOKIE_TIMEOUT_MS);
|
|
185
|
+
}
|
|
186
|
+
function resolveQuoteDepthFromOptions(options) {
|
|
187
|
+
return resolveQuoteDepth(options.quoteDepth, config.quoteDepth, env.BIRD_QUOTE_DEPTH);
|
|
188
|
+
}
|
|
189
|
+
function resolveCredentialsFromOptions(opts) {
|
|
190
|
+
const cookieSource = opts.cookieSource?.length
|
|
191
|
+
? opts.cookieSource
|
|
192
|
+
: (resolveCookieSourceOrder(config.cookieSource) ?? COOKIE_SOURCES);
|
|
193
|
+
const chromeProfile = opts.chromeProfileDir || opts.chromeProfile || config.chromeProfileDir || config.chromeProfile;
|
|
194
|
+
return resolveCredentials({
|
|
195
|
+
authToken: opts.authToken,
|
|
196
|
+
ct0: opts.ct0,
|
|
197
|
+
cookieSource,
|
|
198
|
+
chromeProfile,
|
|
199
|
+
firefoxProfile: opts.firefoxProfile || config.firefoxProfile,
|
|
200
|
+
cookieTimeoutMs: resolveCookieTimeoutFromOptions(opts),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
function loadMedia(opts) {
|
|
204
|
+
if (opts.media.length === 0) {
|
|
205
|
+
return [];
|
|
206
|
+
}
|
|
207
|
+
const specs = [];
|
|
208
|
+
for (const [index, path] of opts.media.entries()) {
|
|
209
|
+
const mime = detectMime(path);
|
|
210
|
+
if (!mime) {
|
|
211
|
+
throw new Error(`Unsupported media type for ${path}. Supported: jpg, jpeg, png, webp, gif, mp4, mov`);
|
|
212
|
+
}
|
|
213
|
+
const buffer = readFileSync(path);
|
|
214
|
+
specs.push({ path, mime, buffer, alt: opts.alts[index] });
|
|
215
|
+
}
|
|
216
|
+
const videoCount = specs.filter((m) => m.mime.startsWith('video/')).length;
|
|
217
|
+
if (videoCount > 1) {
|
|
218
|
+
throw new Error('Only one video can be attached');
|
|
219
|
+
}
|
|
220
|
+
if (videoCount === 1 && specs.length > 1) {
|
|
221
|
+
throw new Error('Video cannot be combined with other media');
|
|
222
|
+
}
|
|
223
|
+
if (specs.length > 4) {
|
|
224
|
+
throw new Error('Maximum 4 media attachments');
|
|
225
|
+
}
|
|
226
|
+
return specs;
|
|
227
|
+
}
|
|
228
|
+
function printTweets(tweets, opts = {}) {
|
|
229
|
+
if (opts.json) {
|
|
230
|
+
console.log(JSON.stringify(tweets, null, 2));
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (tweets.length === 0) {
|
|
234
|
+
console.log(opts.emptyMessage ?? 'No tweets found.');
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const useEmoji = output.emoji && !output.plain;
|
|
238
|
+
const articleLabel = useEmoji ? '📰' : 'Article:';
|
|
239
|
+
const mediaLabel = (type) => {
|
|
240
|
+
if (useEmoji) {
|
|
241
|
+
return type === 'video' ? '🎬' : type === 'animated_gif' ? '🔄' : '🖼️';
|
|
242
|
+
}
|
|
243
|
+
return type === 'video' ? 'VIDEO:' : type === 'animated_gif' ? 'GIF:' : 'PHOTO:';
|
|
244
|
+
};
|
|
245
|
+
const quotePrefix = useEmoji ? { top: '┌─', mid: '│ ', bot: '└─' } : { top: '> ', mid: '> ', bot: '> ' };
|
|
246
|
+
for (const tweet of tweets) {
|
|
247
|
+
console.log(`\n@${tweet.author.username} (${tweet.author.name}):`);
|
|
248
|
+
// Display tweet text, with article indicator if present
|
|
249
|
+
if (tweet.article) {
|
|
250
|
+
// Full body mode: text starts with article title (from extractArticleText)
|
|
251
|
+
// Preview mode: text is short tweet intro that doesn't start with title
|
|
252
|
+
const hasFullBody = tweet.text.startsWith(tweet.article.title);
|
|
253
|
+
if (hasFullBody) {
|
|
254
|
+
console.log(`${articleLabel} ${tweet.text}`);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
console.log(`${articleLabel} ${tweet.article.title}`);
|
|
258
|
+
if (tweet.article.previewText) {
|
|
259
|
+
console.log(` ${tweet.article.previewText}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
console.log(tweet.text);
|
|
265
|
+
}
|
|
266
|
+
// Display media attachments
|
|
267
|
+
if (tweet.media && tweet.media.length > 0) {
|
|
268
|
+
for (const m of tweet.media) {
|
|
269
|
+
console.log(`${mediaLabel(m.type)} ${m.url}`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// Display quoted tweet
|
|
273
|
+
if (tweet.quotedTweet) {
|
|
274
|
+
console.log(`${quotePrefix.top} QT @${tweet.quotedTweet.author.username}:`);
|
|
275
|
+
const qtText = tweet.quotedTweet.article
|
|
276
|
+
? `${articleLabel} ${tweet.quotedTweet.article.title}`
|
|
277
|
+
: tweet.quotedTweet.text;
|
|
278
|
+
// Indent and truncate quoted tweet text
|
|
279
|
+
const maxLen = 280;
|
|
280
|
+
const truncated = qtText.length > maxLen ? `${qtText.slice(0, maxLen)}...` : qtText;
|
|
281
|
+
for (const line of truncated.split('\n').slice(0, 4)) {
|
|
282
|
+
console.log(`${quotePrefix.mid}${line}`);
|
|
283
|
+
}
|
|
284
|
+
// Display quoted tweet media
|
|
285
|
+
if (tweet.quotedTweet.media && tweet.quotedTweet.media.length > 0) {
|
|
286
|
+
for (const m of tweet.quotedTweet.media) {
|
|
287
|
+
console.log(`${quotePrefix.mid}${mediaLabel(m.type)} ${m.url}`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
console.log(`${quotePrefix.bot} https://x.com/${tweet.quotedTweet.author.username}/status/${tweet.quotedTweet.id}`);
|
|
291
|
+
}
|
|
292
|
+
if (tweet.createdAt) {
|
|
293
|
+
console.log(`${l('date')}${tweet.createdAt}`);
|
|
294
|
+
}
|
|
295
|
+
const tweetUrl = `https://x.com/${tweet.author.username}/status/${tweet.id}`;
|
|
296
|
+
console.log(`${l('url')}${hyperlink(tweetUrl, tweetUrl, output)}`);
|
|
297
|
+
if (opts.showSeparator ?? true) {
|
|
298
|
+
console.log('─'.repeat(50));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function printTweetsResult(result, opts) {
|
|
303
|
+
const tweets = result.tweets ?? [];
|
|
304
|
+
if (opts.json && opts.usePagination) {
|
|
305
|
+
console.log(JSON.stringify({ tweets, nextCursor: result.nextCursor ?? null }, null, 2));
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
printTweets(tweets, { json: opts.json, emptyMessage: opts.emptyMessage });
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
isTty,
|
|
312
|
+
getOutput: () => output,
|
|
313
|
+
colors,
|
|
314
|
+
p,
|
|
315
|
+
l,
|
|
316
|
+
config,
|
|
317
|
+
applyOutputFromCommand,
|
|
318
|
+
resolveTimeoutFromOptions,
|
|
319
|
+
resolveQuoteDepthFromOptions,
|
|
320
|
+
resolveCredentialsFromOptions,
|
|
321
|
+
loadMedia,
|
|
322
|
+
printTweets,
|
|
323
|
+
printTweetsResult,
|
|
324
|
+
extractTweetId,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* bird - CLI tool for posting tweets and replies
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* bird tweet "Hello world!"
|
|
7
|
+
* bird reply <tweet-id> "This is a reply"
|
|
8
|
+
* bird reply <tweet-url> "This is a reply"
|
|
9
|
+
* bird read <tweet-id-or-url>
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* bird - CLI tool for posting tweets and replies
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* bird tweet "Hello world!"
|
|
7
|
+
* bird reply <tweet-id> "This is a reply"
|
|
8
|
+
* bird reply <tweet-url> "This is a reply"
|
|
9
|
+
* bird read <tweet-id-or-url>
|
|
10
|
+
*/
|
|
11
|
+
import { createProgram, KNOWN_COMMANDS } from './cli/program.js';
|
|
12
|
+
import { createCliContext } from './cli/shared.js';
|
|
13
|
+
import { resolveCliInvocation } from './lib/cli-args.js';
|
|
14
|
+
const rawArgs = process.argv.slice(2);
|
|
15
|
+
const normalizedArgs = rawArgs[0] === '--' ? rawArgs.slice(1) : rawArgs;
|
|
16
|
+
const ctx = createCliContext(normalizedArgs);
|
|
17
|
+
const program = createProgram(ctx);
|
|
18
|
+
const { argv, showHelp } = resolveCliInvocation(normalizedArgs, KNOWN_COMMANDS);
|
|
19
|
+
if (showHelp) {
|
|
20
|
+
program.outputHelp();
|
|
21
|
+
process.exit(0);
|
|
22
|
+
}
|
|
23
|
+
if (argv) {
|
|
24
|
+
program.parse(argv);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
program.parse(['node', 'bird', ...normalizedArgs]);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=cli.js.map
|