dp-worker 0.1.24 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +3 -0
- package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/bird-contracts.js +14 -0
- package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
- 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,88 @@
|
|
|
1
|
+
const STATUS = {
|
|
2
|
+
ok: { emoji: '✅', text: 'OK:', plain: '[ok]' },
|
|
3
|
+
warn: { emoji: '⚠️', text: 'Warning:', plain: '[warn]' },
|
|
4
|
+
err: { emoji: '❌', text: 'Error:', plain: '[err]' },
|
|
5
|
+
info: { emoji: 'ℹ️', text: 'Info:', plain: '[info]' },
|
|
6
|
+
hint: { emoji: 'ℹ️', text: 'Hint:', plain: '[hint]' },
|
|
7
|
+
};
|
|
8
|
+
const LABELS = {
|
|
9
|
+
url: { emoji: '🔗', text: 'URL:', plain: 'url:' },
|
|
10
|
+
date: { emoji: '📅', text: 'Date:', plain: 'date:' },
|
|
11
|
+
source: { emoji: '📍', text: 'Source:', plain: 'source:' },
|
|
12
|
+
engine: { emoji: '⚙️', text: 'Engine:', plain: 'engine:' },
|
|
13
|
+
credentials: { emoji: '🔑', text: 'Credentials:', plain: 'credentials:' },
|
|
14
|
+
user: { emoji: '🙋', text: 'User:', plain: 'user:' },
|
|
15
|
+
userId: { emoji: '🪪', text: 'User ID:', plain: 'user_id:' },
|
|
16
|
+
email: { emoji: '📧', text: 'Email:', plain: 'email:' },
|
|
17
|
+
};
|
|
18
|
+
export function resolveOutputConfigFromArgv(argv, env, isTty) {
|
|
19
|
+
const hasNoColorEnv = Object.hasOwn(env, 'NO_COLOR') || env.TERM === 'dumb';
|
|
20
|
+
const defaultColor = isTty && !hasNoColorEnv;
|
|
21
|
+
const plain = argv.includes('--plain');
|
|
22
|
+
const emoji = !plain && !argv.includes('--no-emoji');
|
|
23
|
+
const color = !plain && !argv.includes('--no-color') && defaultColor;
|
|
24
|
+
const hyperlinks = !plain && isTty;
|
|
25
|
+
return { plain, emoji, color, hyperlinks };
|
|
26
|
+
}
|
|
27
|
+
export function resolveOutputConfigFromCommander(opts, env, isTty) {
|
|
28
|
+
const hasNoColorEnv = Object.hasOwn(env, 'NO_COLOR') || env.TERM === 'dumb';
|
|
29
|
+
const defaultColor = isTty && !hasNoColorEnv;
|
|
30
|
+
const plain = Boolean(opts.plain);
|
|
31
|
+
const emoji = !plain && (opts.emoji ?? true);
|
|
32
|
+
const color = !plain && (opts.color ?? true) && defaultColor;
|
|
33
|
+
const hyperlinks = !plain && isTty;
|
|
34
|
+
return { plain, emoji, color, hyperlinks };
|
|
35
|
+
}
|
|
36
|
+
export function statusPrefix(kind, cfg) {
|
|
37
|
+
if (cfg.plain) {
|
|
38
|
+
return `${STATUS[kind].plain} `;
|
|
39
|
+
}
|
|
40
|
+
if (cfg.emoji) {
|
|
41
|
+
return `${STATUS[kind].emoji} `;
|
|
42
|
+
}
|
|
43
|
+
return `${STATUS[kind].text} `;
|
|
44
|
+
}
|
|
45
|
+
export function labelPrefix(kind, cfg) {
|
|
46
|
+
if (cfg.plain) {
|
|
47
|
+
return `${LABELS[kind].plain} `;
|
|
48
|
+
}
|
|
49
|
+
if (cfg.emoji) {
|
|
50
|
+
return `${LABELS[kind].emoji} `;
|
|
51
|
+
}
|
|
52
|
+
return `${LABELS[kind].text} `;
|
|
53
|
+
}
|
|
54
|
+
export function formatStatsLine(stats, cfg) {
|
|
55
|
+
const likeCount = stats.likeCount ?? 0;
|
|
56
|
+
const retweetCount = stats.retweetCount ?? 0;
|
|
57
|
+
const replyCount = stats.replyCount ?? 0;
|
|
58
|
+
if (cfg.plain) {
|
|
59
|
+
return `likes: ${likeCount} retweets: ${retweetCount} replies: ${replyCount}`;
|
|
60
|
+
}
|
|
61
|
+
if (!cfg.emoji) {
|
|
62
|
+
return `Likes ${likeCount} Retweets ${retweetCount} Replies ${replyCount}`;
|
|
63
|
+
}
|
|
64
|
+
return `❤️ ${likeCount} 🔁 ${retweetCount} 💬 ${replyCount}`;
|
|
65
|
+
}
|
|
66
|
+
export function formatTweetUrl(tweetId) {
|
|
67
|
+
return `https://x.com/i/status/${tweetId}`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Wraps a URL in OSC 8 escape sequences to make it clickable in supported terminals.
|
|
71
|
+
* Falls back to plain text when not in a TTY or when hyperlinks are disabled.
|
|
72
|
+
*/
|
|
73
|
+
export function hyperlink(url, text, cfg) {
|
|
74
|
+
const displayText = text ?? url;
|
|
75
|
+
// Only use hyperlinks when explicitly enabled (requires TTY and not plain mode)
|
|
76
|
+
if (!cfg?.hyperlinks) {
|
|
77
|
+
return displayText;
|
|
78
|
+
}
|
|
79
|
+
const safeUrl = url.replaceAll('\x1b', '').replaceAll('\x07', '');
|
|
80
|
+
const safeText = displayText.replaceAll('\x1b', '').replaceAll('\x07', '');
|
|
81
|
+
// OSC 8 hyperlink: \x1b]8;;URL\x07TEXT\x1b]8;;\x07
|
|
82
|
+
return `\x1b]8;;${safeUrl}\x07${safeText}\x1b]8;;\x07`;
|
|
83
|
+
}
|
|
84
|
+
export function formatTweetUrlLine(tweetId, cfg) {
|
|
85
|
+
const url = formatTweetUrl(tweetId);
|
|
86
|
+
return `${labelPrefix('url', cfg)}${hyperlink(url, url, cfg)}`;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type CursorPage<T> = {
|
|
2
|
+
success: true;
|
|
3
|
+
items: T[];
|
|
4
|
+
cursor?: string;
|
|
5
|
+
} | {
|
|
6
|
+
success: false;
|
|
7
|
+
error: string;
|
|
8
|
+
};
|
|
9
|
+
export type CursorPaginationResult<T> = {
|
|
10
|
+
success: true;
|
|
11
|
+
items: T[];
|
|
12
|
+
nextCursor?: string;
|
|
13
|
+
} | {
|
|
14
|
+
success: false;
|
|
15
|
+
error: string;
|
|
16
|
+
items?: T[];
|
|
17
|
+
nextCursor?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function paginateCursor<T>(opts: {
|
|
20
|
+
cursor?: string;
|
|
21
|
+
maxPages?: number;
|
|
22
|
+
pageDelayMs?: number;
|
|
23
|
+
sleep: (ms: number) => Promise<void>;
|
|
24
|
+
getKey: (item: T) => string;
|
|
25
|
+
fetchPage: (cursor?: string) => Promise<CursorPage<T>>;
|
|
26
|
+
}): Promise<CursorPaginationResult<T>>;
|
|
27
|
+
//# sourceMappingURL=paginate-cursor.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export async function paginateCursor(opts) {
|
|
2
|
+
const { maxPages, pageDelayMs = 1000 } = opts;
|
|
3
|
+
const seen = new Set();
|
|
4
|
+
const items = [];
|
|
5
|
+
let cursor = opts.cursor;
|
|
6
|
+
let pagesFetched = 0;
|
|
7
|
+
while (true) {
|
|
8
|
+
if (pagesFetched > 0 && pageDelayMs > 0) {
|
|
9
|
+
await opts.sleep(pageDelayMs);
|
|
10
|
+
}
|
|
11
|
+
const page = await opts.fetchPage(cursor);
|
|
12
|
+
if (!page.success) {
|
|
13
|
+
if (items.length > 0) {
|
|
14
|
+
return { success: false, error: page.error, items, nextCursor: cursor };
|
|
15
|
+
}
|
|
16
|
+
return page;
|
|
17
|
+
}
|
|
18
|
+
pagesFetched += 1;
|
|
19
|
+
for (const item of page.items) {
|
|
20
|
+
const key = opts.getKey(item);
|
|
21
|
+
if (seen.has(key)) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
seen.add(key);
|
|
25
|
+
items.push(item);
|
|
26
|
+
}
|
|
27
|
+
const pageCursor = page.cursor;
|
|
28
|
+
if (!pageCursor || pageCursor === cursor) {
|
|
29
|
+
return { success: true, items, nextCursor: undefined };
|
|
30
|
+
}
|
|
31
|
+
if (maxPages !== undefined && pagesFetched >= maxPages) {
|
|
32
|
+
return { success: true, items, nextCursor: pageCursor };
|
|
33
|
+
}
|
|
34
|
+
cursor = pageCursor;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=paginate-cursor.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"CreateTweet": "nmdAQXJDxw6-0KKF2on7eA",
|
|
3
|
+
"CreateRetweet": "LFho5rIi4xcKO90p9jwG7A",
|
|
4
|
+
"CreateFriendship": "8h9JVdV8dlSyqyRDJEPCsA",
|
|
5
|
+
"DestroyFriendship": "ppXWuagMNXgvzx6WoXBW0Q",
|
|
6
|
+
"FavoriteTweet": "lI07N6Otwv1PhnEgXILM7A",
|
|
7
|
+
"DeleteBookmark": "Wlmlj2-xzyS1GN3a6cj-mQ",
|
|
8
|
+
"TweetDetail": "_NvJCnIjOW__EP5-RF197A",
|
|
9
|
+
"SearchTimeline": "6AAys3t42mosm_yTI_QENg",
|
|
10
|
+
"Bookmarks": "RV1g3b8n_SGOHwkqKYSCFw",
|
|
11
|
+
"BookmarkFolderTimeline": "KJIQpsvxrTfRIlbaRIySHQ",
|
|
12
|
+
"Following": "mWYeougg_ocJS2Vr1Vt28w",
|
|
13
|
+
"Followers": "SFYY3WsgwjlXSLlfnEUE4A",
|
|
14
|
+
"Likes": "ETJflBunfqNa1uE1mBPCaw",
|
|
15
|
+
"ExploreSidebar": "lpSN4M6qpimkF4nRFPE3nQ",
|
|
16
|
+
"ExplorePage": "kheAINB_4pzRDqkzG3K-ng",
|
|
17
|
+
"GenericTimelineById": "uGSr7alSjR9v6QJAIaqSKQ",
|
|
18
|
+
"TrendHistory": "Sj4T-jSB9pr0Mxtsc1UKZQ",
|
|
19
|
+
"AboutAccountQuery": "zs_jFPFT78rBpXv9Z3U2YQ"
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type FeatureOverrides = {
|
|
2
|
+
global?: Record<string, boolean>;
|
|
3
|
+
sets?: Record<string, Record<string, boolean>>;
|
|
4
|
+
};
|
|
5
|
+
type NormalizedFeatureOverrides = {
|
|
6
|
+
global: Record<string, boolean>;
|
|
7
|
+
sets: Record<string, Record<string, boolean>>;
|
|
8
|
+
};
|
|
9
|
+
export type FeatureOverridesSnapshot = {
|
|
10
|
+
cachePath: string;
|
|
11
|
+
overrides: FeatureOverrides;
|
|
12
|
+
};
|
|
13
|
+
export declare function loadFeatureOverrides(): NormalizedFeatureOverrides;
|
|
14
|
+
export declare function getFeatureOverridesSnapshot(): FeatureOverridesSnapshot;
|
|
15
|
+
export declare function applyFeatureOverrides(setName: string, base: Record<string, boolean>): Record<string, boolean>;
|
|
16
|
+
export declare function refreshFeatureOverridesCache(): Promise<FeatureOverridesSnapshot>;
|
|
17
|
+
export declare function clearFeatureOverridesCache(): void;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=runtime-features.d.ts.map
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
// biome-ignore lint/correctness/useImportExtensions: JSON module import doesn't use .js extension.
|
|
6
|
+
import defaultOverrides from './features.json' with { type: 'json' };
|
|
7
|
+
const DEFAULT_CACHE_FILENAME = 'features.json';
|
|
8
|
+
let cachedOverrides = null;
|
|
9
|
+
function normalizeFeatureMap(value) {
|
|
10
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
const result = {};
|
|
14
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
15
|
+
if (typeof entry === 'boolean') {
|
|
16
|
+
result[key] = entry;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
function normalizeOverrides(value) {
|
|
22
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
23
|
+
return { global: {}, sets: {} };
|
|
24
|
+
}
|
|
25
|
+
const record = value;
|
|
26
|
+
const global = normalizeFeatureMap(record.global);
|
|
27
|
+
const sets = {};
|
|
28
|
+
const rawSets = record.sets && typeof record.sets === 'object' && !Array.isArray(record.sets)
|
|
29
|
+
? record.sets
|
|
30
|
+
: {};
|
|
31
|
+
for (const [setName, setValue] of Object.entries(rawSets)) {
|
|
32
|
+
const normalized = normalizeFeatureMap(setValue);
|
|
33
|
+
if (Object.keys(normalized).length > 0) {
|
|
34
|
+
sets[setName] = normalized;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { global, sets };
|
|
38
|
+
}
|
|
39
|
+
function mergeOverrides(base, next) {
|
|
40
|
+
const sets = { ...base.sets };
|
|
41
|
+
for (const [setName, overrides] of Object.entries(next.sets)) {
|
|
42
|
+
const existing = sets[setName];
|
|
43
|
+
sets[setName] = existing ? { ...existing, ...overrides } : { ...overrides };
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
global: { ...base.global, ...next.global },
|
|
47
|
+
sets,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function toFeatureOverrides(overrides) {
|
|
51
|
+
const result = {};
|
|
52
|
+
if (Object.keys(overrides.global).length > 0) {
|
|
53
|
+
result.global = overrides.global;
|
|
54
|
+
}
|
|
55
|
+
const setEntries = Object.entries(overrides.sets).filter(([, value]) => Object.keys(value).length > 0);
|
|
56
|
+
if (setEntries.length > 0) {
|
|
57
|
+
result.sets = Object.fromEntries(setEntries);
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
function resolveFeaturesCachePath() {
|
|
62
|
+
const override = process.env.BIRD_FEATURES_CACHE ?? process.env.BIRD_FEATURES_PATH;
|
|
63
|
+
if (override && override.trim().length > 0) {
|
|
64
|
+
return path.resolve(override.trim());
|
|
65
|
+
}
|
|
66
|
+
return path.join(homedir(), '.config', 'bird', DEFAULT_CACHE_FILENAME);
|
|
67
|
+
}
|
|
68
|
+
function readOverridesFromFile(cachePath) {
|
|
69
|
+
if (!existsSync(cachePath)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const raw = readFileSync(cachePath, 'utf8');
|
|
74
|
+
return normalizeOverrides(JSON.parse(raw));
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function readOverridesFromEnv() {
|
|
81
|
+
const raw = process.env.BIRD_FEATURES_JSON;
|
|
82
|
+
if (!raw || raw.trim().length === 0) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
return normalizeOverrides(JSON.parse(raw));
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function writeOverridesToDisk(cachePath, overrides) {
|
|
93
|
+
const payload = toFeatureOverrides(overrides);
|
|
94
|
+
return mkdir(path.dirname(cachePath), { recursive: true }).then(() => writeFile(cachePath, `${JSON.stringify(payload, null, 2)}\n`, 'utf8'));
|
|
95
|
+
}
|
|
96
|
+
export function loadFeatureOverrides() {
|
|
97
|
+
if (cachedOverrides) {
|
|
98
|
+
return cachedOverrides;
|
|
99
|
+
}
|
|
100
|
+
const base = normalizeOverrides(defaultOverrides);
|
|
101
|
+
const fromFile = readOverridesFromFile(resolveFeaturesCachePath());
|
|
102
|
+
const fromEnv = readOverridesFromEnv();
|
|
103
|
+
let merged = base;
|
|
104
|
+
if (fromFile) {
|
|
105
|
+
merged = mergeOverrides(merged, fromFile);
|
|
106
|
+
}
|
|
107
|
+
if (fromEnv) {
|
|
108
|
+
merged = mergeOverrides(merged, fromEnv);
|
|
109
|
+
}
|
|
110
|
+
cachedOverrides = merged;
|
|
111
|
+
return merged;
|
|
112
|
+
}
|
|
113
|
+
export function getFeatureOverridesSnapshot() {
|
|
114
|
+
const overrides = toFeatureOverrides(loadFeatureOverrides());
|
|
115
|
+
return {
|
|
116
|
+
cachePath: resolveFeaturesCachePath(),
|
|
117
|
+
overrides,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
export function applyFeatureOverrides(setName, base) {
|
|
121
|
+
const overrides = loadFeatureOverrides();
|
|
122
|
+
const globalOverrides = overrides.global;
|
|
123
|
+
const setOverrides = overrides.sets[setName];
|
|
124
|
+
if (Object.keys(globalOverrides).length === 0 && (!setOverrides || Object.keys(setOverrides).length === 0)) {
|
|
125
|
+
return base;
|
|
126
|
+
}
|
|
127
|
+
if (setOverrides) {
|
|
128
|
+
return {
|
|
129
|
+
...base,
|
|
130
|
+
...globalOverrides,
|
|
131
|
+
...setOverrides,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
...base,
|
|
136
|
+
...globalOverrides,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export async function refreshFeatureOverridesCache() {
|
|
140
|
+
const cachePath = resolveFeaturesCachePath();
|
|
141
|
+
const base = normalizeOverrides(defaultOverrides);
|
|
142
|
+
const fromFile = readOverridesFromFile(cachePath);
|
|
143
|
+
const merged = mergeOverrides(base, fromFile ?? { global: {}, sets: {} });
|
|
144
|
+
await writeOverridesToDisk(cachePath, merged);
|
|
145
|
+
cachedOverrides = null;
|
|
146
|
+
return { cachePath, overrides: toFeatureOverrides(merged) };
|
|
147
|
+
}
|
|
148
|
+
export function clearFeatureOverridesCache() {
|
|
149
|
+
cachedOverrides = null;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=runtime-features.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type RuntimeQueryIdSnapshot = {
|
|
2
|
+
fetchedAt: string;
|
|
3
|
+
ttlMs: number;
|
|
4
|
+
ids: Record<string, string>;
|
|
5
|
+
discovery: {
|
|
6
|
+
pages: string[];
|
|
7
|
+
bundles: string[];
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export type RuntimeQueryIdSnapshotInfo = {
|
|
11
|
+
snapshot: RuntimeQueryIdSnapshot;
|
|
12
|
+
cachePath: string;
|
|
13
|
+
ageMs: number;
|
|
14
|
+
isFresh: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type RuntimeQueryIdsOptions = {
|
|
17
|
+
cachePath?: string;
|
|
18
|
+
ttlMs?: number;
|
|
19
|
+
fetchImpl?: typeof fetch;
|
|
20
|
+
};
|
|
21
|
+
export type RuntimeQueryIdStore = {
|
|
22
|
+
cachePath: string;
|
|
23
|
+
ttlMs: number;
|
|
24
|
+
getSnapshotInfo: () => Promise<RuntimeQueryIdSnapshotInfo | null>;
|
|
25
|
+
getQueryId: (operationName: string) => Promise<string | null>;
|
|
26
|
+
refresh: (operationNames: string[], opts?: {
|
|
27
|
+
force?: boolean;
|
|
28
|
+
}) => Promise<RuntimeQueryIdSnapshotInfo | null>;
|
|
29
|
+
clearMemory: () => void;
|
|
30
|
+
};
|
|
31
|
+
export declare function createRuntimeQueryIdStore(options?: RuntimeQueryIdsOptions): RuntimeQueryIdStore;
|
|
32
|
+
export declare const runtimeQueryIds: RuntimeQueryIdStore;
|
|
33
|
+
//# sourceMappingURL=runtime-query-ids.d.ts.map
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
const DEFAULT_CACHE_FILENAME = 'query-ids-cache.json';
|
|
5
|
+
const DEFAULT_TTL_MS = 24 * 60 * 60 * 1000;
|
|
6
|
+
const DISCOVERY_PAGES = [
|
|
7
|
+
'https://x.com/?lang=en',
|
|
8
|
+
'https://x.com/explore',
|
|
9
|
+
'https://x.com/notifications',
|
|
10
|
+
'https://x.com/settings/profile',
|
|
11
|
+
];
|
|
12
|
+
const BUNDLE_URL_REGEX = /https:\/\/abs\.twimg\.com\/responsive-web\/client-web(?:-legacy)?\/[A-Za-z0-9.-]+\.js/g;
|
|
13
|
+
const QUERY_ID_REGEX = /^[a-zA-Z0-9_-]+$/;
|
|
14
|
+
const OPERATION_PATTERNS = [
|
|
15
|
+
{
|
|
16
|
+
regex: /e\.exports=\{queryId\s*:\s*["']([^"']+)["']\s*,\s*operationName\s*:\s*["']([^"']+)["']/gs,
|
|
17
|
+
operationGroup: 2,
|
|
18
|
+
queryIdGroup: 1,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
regex: /e\.exports=\{operationName\s*:\s*["']([^"']+)["']\s*,\s*queryId\s*:\s*["']([^"']+)["']/gs,
|
|
22
|
+
operationGroup: 1,
|
|
23
|
+
queryIdGroup: 2,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
regex: /operationName\s*[:=]\s*["']([^"']+)["'](.{0,4000}?)queryId\s*[:=]\s*["']([^"']+)["']/gs,
|
|
27
|
+
operationGroup: 1,
|
|
28
|
+
queryIdGroup: 3,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
regex: /queryId\s*[:=]\s*["']([^"']+)["'](.{0,4000}?)operationName\s*[:=]\s*["']([^"']+)["']/gs,
|
|
32
|
+
operationGroup: 3,
|
|
33
|
+
queryIdGroup: 1,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
const HEADERS = {
|
|
37
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36',
|
|
38
|
+
Accept: 'text/html,application/json;q=0.9,*/*;q=0.8',
|
|
39
|
+
'Accept-Language': 'en-US,en;q=0.9',
|
|
40
|
+
};
|
|
41
|
+
async function fetchText(fetchImpl, url) {
|
|
42
|
+
const response = await fetchImpl(url, { headers: HEADERS });
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
const body = await response.text().catch(() => '');
|
|
45
|
+
throw new Error(`HTTP ${response.status} for ${url}: ${body.slice(0, 120)}`);
|
|
46
|
+
}
|
|
47
|
+
return response.text();
|
|
48
|
+
}
|
|
49
|
+
function resolveDefaultCachePath() {
|
|
50
|
+
const override = process.env.BIRD_QUERY_IDS_CACHE;
|
|
51
|
+
if (override && override.trim().length > 0) {
|
|
52
|
+
return path.resolve(override.trim());
|
|
53
|
+
}
|
|
54
|
+
return path.join(homedir(), '.config', 'bird', DEFAULT_CACHE_FILENAME);
|
|
55
|
+
}
|
|
56
|
+
function parseSnapshot(raw) {
|
|
57
|
+
if (!raw || typeof raw !== 'object') {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const record = raw;
|
|
61
|
+
const fetchedAt = typeof record.fetchedAt === 'string' ? record.fetchedAt : null;
|
|
62
|
+
const ttlMs = typeof record.ttlMs === 'number' && Number.isFinite(record.ttlMs) ? record.ttlMs : null;
|
|
63
|
+
const ids = record.ids && typeof record.ids === 'object' ? record.ids : null;
|
|
64
|
+
const discovery = record.discovery && typeof record.discovery === 'object' ? record.discovery : null;
|
|
65
|
+
if (!fetchedAt || !ttlMs || !ids || !discovery) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const pages = Array.isArray(discovery.pages) ? discovery.pages : null;
|
|
69
|
+
const bundles = Array.isArray(discovery.bundles) ? discovery.bundles : null;
|
|
70
|
+
if (!pages || !bundles) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const normalizedIds = {};
|
|
74
|
+
for (const [key, value] of Object.entries(ids)) {
|
|
75
|
+
if (typeof value === 'string' && value.trim().length > 0) {
|
|
76
|
+
normalizedIds[key] = value.trim();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
fetchedAt,
|
|
81
|
+
ttlMs,
|
|
82
|
+
ids: normalizedIds,
|
|
83
|
+
discovery: {
|
|
84
|
+
pages: pages.filter((p) => typeof p === 'string'),
|
|
85
|
+
bundles: bundles.filter((b) => typeof b === 'string'),
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async function readSnapshotFromDisk(cachePath) {
|
|
90
|
+
try {
|
|
91
|
+
const raw = await readFile(cachePath, 'utf8');
|
|
92
|
+
return parseSnapshot(JSON.parse(raw));
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function writeSnapshotToDisk(cachePath, snapshot) {
|
|
99
|
+
await mkdir(path.dirname(cachePath), { recursive: true });
|
|
100
|
+
await writeFile(cachePath, `${JSON.stringify(snapshot, null, 2)}\n`, 'utf8');
|
|
101
|
+
}
|
|
102
|
+
async function discoverBundles(fetchImpl) {
|
|
103
|
+
const bundles = new Set();
|
|
104
|
+
for (const page of DISCOVERY_PAGES) {
|
|
105
|
+
try {
|
|
106
|
+
const html = await fetchText(fetchImpl, page);
|
|
107
|
+
for (const match of html.matchAll(BUNDLE_URL_REGEX)) {
|
|
108
|
+
bundles.add(match[0]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// ignore discovery page failures; other pages often work
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const discovered = [...bundles];
|
|
116
|
+
if (discovered.length === 0) {
|
|
117
|
+
throw new Error('No client bundles discovered; x.com layout may have changed.');
|
|
118
|
+
}
|
|
119
|
+
return discovered;
|
|
120
|
+
}
|
|
121
|
+
function extractOperations(bundleContents, bundleLabel, targets, discovered) {
|
|
122
|
+
for (const pattern of OPERATION_PATTERNS) {
|
|
123
|
+
pattern.regex.lastIndex = 0;
|
|
124
|
+
while (true) {
|
|
125
|
+
const match = pattern.regex.exec(bundleContents);
|
|
126
|
+
if (match === null) {
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
const operationName = match[pattern.operationGroup];
|
|
130
|
+
const queryId = match[pattern.queryIdGroup];
|
|
131
|
+
if (!operationName || !queryId) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (!targets.has(operationName)) {
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (!QUERY_ID_REGEX.test(queryId)) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (discovered.has(operationName)) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
discovered.set(operationName, { queryId, bundle: bundleLabel });
|
|
144
|
+
if (discovered.size === targets.size) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async function fetchAndExtract(fetchImpl, bundleUrls, targets) {
|
|
151
|
+
const discovered = new Map();
|
|
152
|
+
const CONCURRENCY = 6;
|
|
153
|
+
for (let i = 0; i < bundleUrls.length; i += CONCURRENCY) {
|
|
154
|
+
const chunk = bundleUrls.slice(i, i + CONCURRENCY);
|
|
155
|
+
await Promise.all(chunk.map(async (url) => {
|
|
156
|
+
if (discovered.size === targets.size) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const label = url.split('/').at(-1) ?? url;
|
|
160
|
+
try {
|
|
161
|
+
const js = await fetchText(fetchImpl, url);
|
|
162
|
+
extractOperations(js, label, targets, discovered);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
// ignore failed bundles
|
|
166
|
+
}
|
|
167
|
+
}));
|
|
168
|
+
if (discovered.size === targets.size) {
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return discovered;
|
|
173
|
+
}
|
|
174
|
+
export function createRuntimeQueryIdStore(options = {}) {
|
|
175
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
176
|
+
const ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
|
|
177
|
+
const cachePath = options.cachePath ? path.resolve(options.cachePath) : resolveDefaultCachePath();
|
|
178
|
+
let memorySnapshot = null;
|
|
179
|
+
let loadOnce = null;
|
|
180
|
+
let refreshInFlight = null;
|
|
181
|
+
const loadSnapshot = async () => {
|
|
182
|
+
if (memorySnapshot) {
|
|
183
|
+
return memorySnapshot;
|
|
184
|
+
}
|
|
185
|
+
if (!loadOnce) {
|
|
186
|
+
loadOnce = (async () => {
|
|
187
|
+
const fromDisk = await readSnapshotFromDisk(cachePath);
|
|
188
|
+
memorySnapshot = fromDisk;
|
|
189
|
+
return fromDisk;
|
|
190
|
+
})();
|
|
191
|
+
}
|
|
192
|
+
return loadOnce;
|
|
193
|
+
};
|
|
194
|
+
const getSnapshotInfo = async () => {
|
|
195
|
+
const snapshot = await loadSnapshot();
|
|
196
|
+
if (!snapshot) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
const fetchedAtMs = new Date(snapshot.fetchedAt).getTime();
|
|
200
|
+
const ageMs = Number.isFinite(fetchedAtMs) ? Math.max(0, Date.now() - fetchedAtMs) : Number.POSITIVE_INFINITY;
|
|
201
|
+
const effectiveTtl = Number.isFinite(snapshot.ttlMs) ? snapshot.ttlMs : ttlMs;
|
|
202
|
+
const isFresh = ageMs <= effectiveTtl;
|
|
203
|
+
return { snapshot, cachePath, ageMs, isFresh };
|
|
204
|
+
};
|
|
205
|
+
const getQueryId = async (operationName) => {
|
|
206
|
+
const info = await getSnapshotInfo();
|
|
207
|
+
if (!info) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
return info.snapshot.ids[operationName] ?? null;
|
|
211
|
+
};
|
|
212
|
+
const refresh = async (operationNames, opts = {}) => {
|
|
213
|
+
if (refreshInFlight) {
|
|
214
|
+
return refreshInFlight;
|
|
215
|
+
}
|
|
216
|
+
refreshInFlight = (async () => {
|
|
217
|
+
const current = await getSnapshotInfo();
|
|
218
|
+
if (!opts.force && current?.isFresh) {
|
|
219
|
+
return current;
|
|
220
|
+
}
|
|
221
|
+
const targets = new Set(operationNames);
|
|
222
|
+
const bundleUrls = await discoverBundles(fetchImpl);
|
|
223
|
+
const discovered = await fetchAndExtract(fetchImpl, bundleUrls, targets);
|
|
224
|
+
if (discovered.size === 0) {
|
|
225
|
+
return current ?? null;
|
|
226
|
+
}
|
|
227
|
+
const ids = {};
|
|
228
|
+
for (const name of operationNames) {
|
|
229
|
+
const entry = discovered.get(name);
|
|
230
|
+
if (entry?.queryId) {
|
|
231
|
+
ids[name] = entry.queryId;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const snapshot = {
|
|
235
|
+
fetchedAt: new Date().toISOString(),
|
|
236
|
+
ttlMs,
|
|
237
|
+
ids,
|
|
238
|
+
discovery: {
|
|
239
|
+
pages: [...DISCOVERY_PAGES],
|
|
240
|
+
bundles: bundleUrls.map((url) => url.split('/').at(-1) ?? url),
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
await writeSnapshotToDisk(cachePath, snapshot);
|
|
244
|
+
memorySnapshot = snapshot;
|
|
245
|
+
return getSnapshotInfo();
|
|
246
|
+
})().finally(() => {
|
|
247
|
+
refreshInFlight = null;
|
|
248
|
+
});
|
|
249
|
+
return refreshInFlight;
|
|
250
|
+
};
|
|
251
|
+
return {
|
|
252
|
+
cachePath,
|
|
253
|
+
ttlMs,
|
|
254
|
+
getSnapshotInfo,
|
|
255
|
+
getQueryId,
|
|
256
|
+
refresh,
|
|
257
|
+
clearMemory() {
|
|
258
|
+
memorySnapshot = null;
|
|
259
|
+
loadOnce = null;
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
export const runtimeQueryIds = createRuntimeQueryIdStore();
|
|
264
|
+
//# sourceMappingURL=runtime-query-ids.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TweetData, TweetWithMeta } from './twitter-client-types.js';
|
|
2
|
+
export declare function filterAuthorChain(tweets: TweetData[], bookmarkedTweet: TweetData): TweetData[];
|
|
3
|
+
export declare function filterAuthorOnly(tweets: TweetData[], bookmarkedTweet: TweetData): TweetData[];
|
|
4
|
+
export declare function filterFullChain(tweets: TweetData[], bookmarkedTweet: TweetData, options?: {
|
|
5
|
+
includeAncestorBranches?: boolean;
|
|
6
|
+
}): TweetData[];
|
|
7
|
+
export declare function addThreadMetadata(tweet: TweetData, allConversationTweets: TweetData[]): TweetWithMeta;
|
|
8
|
+
//# sourceMappingURL=thread-filters.d.ts.map
|