@jackwener/opencli 1.7.22 → 1.8.1
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/README.md +35 -194
- package/README.zh-CN.md +42 -260
- package/cli-manifest.json +8160 -4392
- package/clis/12306/me.js +73 -0
- package/clis/12306/orders.js +96 -0
- package/clis/12306/passengers.js +90 -0
- package/clis/12306/price.js +166 -0
- package/clis/12306/stations.js +66 -0
- package/clis/12306/train.js +91 -0
- package/clis/12306/trains.js +119 -0
- package/clis/12306/utils.js +272 -0
- package/clis/12306/utils.test.js +331 -0
- package/clis/36kr/article.js +6 -3
- package/clis/36kr/article.test.js +46 -0
- package/clis/_atlassian/shared.js +577 -0
- package/clis/_atlassian/shared.test.js +170 -0
- package/clis/apple-podcasts/commands.test.js +20 -0
- package/clis/apple-podcasts/search.js +2 -2
- package/clis/barchart/greeks.js +144 -56
- package/clis/barchart/greeks.test.js +138 -0
- package/clis/bilibili/comment.js +125 -0
- package/clis/bilibili/comment.test.js +153 -0
- package/clis/bilibili/comments.js +116 -21
- package/clis/bilibili/comments.test.js +77 -18
- package/clis/bilibili/subtitle.js +76 -31
- package/clis/bilibili/subtitle.test.js +156 -9
- package/clis/bilibili/summary.js +167 -0
- package/clis/bilibili/summary.test.js +210 -0
- package/clis/bilibili/utils.js +63 -5
- package/clis/bilibili/utils.test.js +45 -1
- package/clis/booking/booking.test.js +356 -0
- package/clis/booking/search.js +351 -0
- package/clis/chatgpt/envelope.test.js +108 -0
- package/clis/chatgpt/image.js +2 -2
- package/clis/chatgpt/image.test.js +6 -0
- package/clis/chatgpt/utils.js +148 -41
- package/clis/chatgpt/utils.test.js +92 -2
- package/clis/chess/analyze.js +35 -0
- package/clis/chess/analyze.test.js +79 -0
- package/clis/chess/game.js +114 -0
- package/clis/chess/game.test.js +178 -0
- package/clis/chess/games.js +67 -0
- package/clis/chess/games.test.js +164 -0
- package/clis/chess/stats.js +32 -0
- package/clis/chess/stats.test.js +79 -0
- package/clis/chess/utils.js +170 -0
- package/clis/chess/utils.test.js +230 -0
- package/clis/confluence/commands.test.js +195 -0
- package/clis/confluence/create.js +39 -0
- package/clis/confluence/page.js +23 -0
- package/clis/confluence/search.js +34 -0
- package/clis/confluence/shared.js +173 -0
- package/clis/confluence/update.js +38 -0
- package/clis/douyin/_shared/browser-fetch.js +44 -20
- package/clis/douyin/_shared/browser-fetch.test.js +22 -1
- package/clis/douyin/_shared/evaluate-result.js +16 -0
- package/clis/douyin/_shared/tos-upload.js +105 -69
- package/clis/douyin/_shared/vod-upload.js +212 -0
- package/clis/douyin/_shared/vod-upload.test.js +38 -0
- package/clis/douyin/delete.js +137 -4
- package/clis/douyin/delete.test.js +90 -1
- package/clis/douyin/hashtag.js +84 -23
- package/clis/douyin/hashtag.test.js +113 -0
- package/clis/douyin/publish-upload-id.test.js +170 -0
- package/clis/douyin/publish.js +88 -42
- package/clis/douyin/user-videos.js +9 -2
- package/clis/douyin/user-videos.test.js +43 -0
- package/clis/flomo/memos.js +228 -0
- package/clis/flomo/memos.test.js +144 -0
- package/clis/geogebra/add-circle.js +46 -0
- package/clis/geogebra/add-line.js +35 -0
- package/clis/geogebra/add-point.js +27 -0
- package/clis/geogebra/add-polygon.js +25 -0
- package/clis/geogebra/eval.js +35 -0
- package/clis/geogebra/geogebra.test.js +175 -0
- package/clis/geogebra/hexagon.js +62 -0
- package/clis/geogebra/info.js +72 -0
- package/clis/geogebra/list.js +35 -0
- package/clis/geogebra/triangle.js +60 -0
- package/clis/geogebra/utils.js +271 -0
- package/clis/gitee/search.js +2 -2
- package/clis/gitee/search.test.js +65 -0
- package/clis/jike/post.js +27 -17
- package/clis/jike/read.test.js +86 -0
- package/clis/jike/topic.js +32 -19
- package/clis/jike/user.js +33 -20
- package/clis/jira/attachments.js +28 -0
- package/clis/jira/commands.test.js +287 -0
- package/clis/jira/comments.js +28 -0
- package/clis/jira/issue.js +28 -0
- package/clis/jira/links.js +28 -0
- package/clis/jira/search.js +47 -0
- package/clis/jira/shared.js +256 -0
- package/clis/lesswrong/comments.js +1 -1
- package/clis/lesswrong/curated.js +1 -1
- package/clis/lesswrong/frontpage.js +1 -1
- package/clis/lesswrong/frontpage.test.js +37 -0
- package/clis/lesswrong/new.js +1 -1
- package/clis/lesswrong/read.js +1 -1
- package/clis/lesswrong/sequences.js +1 -1
- package/clis/lesswrong/shortform.js +1 -1
- package/clis/lesswrong/tag.js +1 -1
- package/clis/lesswrong/top-month.js +1 -1
- package/clis/lesswrong/top-week.js +1 -1
- package/clis/lesswrong/top-year.js +1 -1
- package/clis/lesswrong/top.js +1 -1
- package/clis/linkedin/connect.js +401 -0
- package/clis/linkedin/connect.test.js +213 -0
- package/clis/linkedin/inbox.js +234 -0
- package/clis/linkedin/inbox.test.js +152 -0
- package/clis/linkedin/job-detail.js +167 -0
- package/clis/linkedin/job-detail.test.js +38 -0
- package/clis/linkedin/jobs-preferences.js +113 -0
- package/clis/linkedin/jobs-preferences.test.js +43 -0
- package/clis/linkedin/people-search.js +262 -0
- package/clis/linkedin/people-search.test.js +216 -0
- package/clis/linkedin/post-analytics.js +74 -0
- package/clis/linkedin/post-analytics.test.js +40 -0
- package/clis/linkedin/posts-core.js +241 -0
- package/clis/linkedin/posts.js +22 -0
- package/clis/linkedin/posts.test.js +40 -0
- package/clis/linkedin/profile-analytics.js +104 -0
- package/clis/linkedin/profile-analytics.test.js +67 -0
- package/clis/linkedin/profile-experience.js +671 -0
- package/clis/linkedin/profile-experience.test.js +152 -0
- package/clis/linkedin/profile-projects.js +311 -0
- package/clis/linkedin/profile-projects.test.js +111 -0
- package/clis/linkedin/profile-read.js +148 -0
- package/clis/linkedin/profile-read.test.js +77 -0
- package/clis/linkedin/safe-send.js +357 -0
- package/clis/linkedin/safe-send.test.js +204 -0
- package/clis/linkedin/salesnav-inbox.js +210 -0
- package/clis/linkedin/salesnav-inbox.test.js +113 -0
- package/clis/linkedin/salesnav-message.js +360 -0
- package/clis/linkedin/salesnav-message.test.js +172 -0
- package/clis/linkedin/salesnav-search.js +186 -0
- package/clis/linkedin/salesnav-search.test.js +76 -0
- package/clis/linkedin/salesnav-thread.js +212 -0
- package/clis/linkedin/salesnav-thread.test.js +79 -0
- package/clis/linkedin/sent-invitations.js +92 -0
- package/clis/linkedin/sent-invitations.test.js +62 -0
- package/clis/linkedin/services-read.js +213 -0
- package/clis/linkedin/services-read.test.js +105 -0
- package/clis/linkedin/shared.js +124 -0
- package/clis/linkedin/thread-snapshot.js +214 -0
- package/clis/linkedin/thread-snapshot.test.js +89 -0
- package/clis/linkedin/timeline.js +14 -7
- package/clis/linkedin-learning/course.js +138 -0
- package/clis/linkedin-learning/course.test.js +114 -0
- package/clis/linkedin-learning/search.js +155 -0
- package/clis/linkedin-learning/search.test.js +144 -0
- package/clis/linkedin-learning/trending.js +133 -0
- package/clis/linkedin-learning/trending.test.js +123 -0
- package/clis/notebooklm/add-source.js +269 -0
- package/clis/notebooklm/add-source.test.js +97 -0
- package/clis/notebooklm/create.js +76 -0
- package/clis/notebooklm/create.test.js +58 -0
- package/clis/notebooklm/generate-audio.js +91 -0
- package/clis/notebooklm/generate-audio.test.js +63 -0
- package/clis/notebooklm/generate-slides.js +106 -0
- package/clis/notebooklm/generate-slides.test.js +75 -0
- package/clis/notebooklm/open.test.js +10 -10
- package/clis/notebooklm/rpc.js +20 -6
- package/clis/notebooklm/rpc.test.js +27 -1
- package/clis/notebooklm/utils.js +100 -24
- package/clis/notebooklm/utils.test.js +60 -1
- package/clis/notebooklm/write-note.js +103 -0
- package/clis/notebooklm/write-note.test.js +70 -0
- package/clis/pixiv/detail.js +41 -34
- package/clis/pixiv/detail.test.js +93 -0
- package/clis/pixiv/user.js +36 -31
- package/clis/pixiv/user.test.js +100 -0
- package/clis/pixiv/utils.js +56 -7
- package/clis/powerchina/search.js +3 -3
- package/clis/powerchina/search.test.js +27 -1
- package/clis/reddit/extract-media.test.js +149 -0
- package/clis/reddit/frontpage.js +47 -9
- package/clis/reddit/frontpage.test.js +34 -0
- package/clis/reddit/home.js +31 -1
- package/clis/reddit/home.test.js +46 -3
- package/clis/reddit/hot.js +32 -1
- package/clis/reddit/hot.test.js +15 -1
- package/clis/reddit/popular.js +39 -1
- package/clis/reddit/popular.test.js +26 -0
- package/clis/reddit/saved.js +1 -1
- package/clis/reddit/search.js +38 -1
- package/clis/reddit/search.test.js +26 -0
- package/clis/reddit/subreddit.js +52 -7
- package/clis/reddit/subreddit.test.js +31 -0
- package/clis/reddit/subscribed.js +165 -0
- package/clis/reddit/subscribed.test.js +168 -0
- package/clis/reddit/upvoted.js +1 -1
- package/clis/suno/commands.test.js +188 -0
- package/clis/suno/download.js +140 -0
- package/clis/suno/download.test.js +151 -0
- package/clis/suno/generate.js +231 -0
- package/clis/suno/generate.test.js +252 -0
- package/clis/suno/list.js +79 -0
- package/clis/suno/status.js +63 -0
- package/clis/suno/utils.js +549 -0
- package/clis/suno/utils.test.js +329 -0
- package/clis/twitter/device-follow.js +193 -0
- package/clis/twitter/device-follow.test.js +287 -0
- package/clis/twitter/download.js +443 -73
- package/clis/twitter/download.test.js +457 -0
- package/clis/twitter/followers.js +6 -2
- package/clis/twitter/followers.test.js +19 -1
- package/clis/twitter/following.js +14 -5
- package/clis/twitter/following.test.js +29 -0
- package/clis/twitter/likes.js +12 -4
- package/clis/twitter/likes.test.js +26 -1
- package/clis/twitter/list-add.js +1 -1
- package/clis/twitter/list-create.js +155 -0
- package/clis/twitter/list-create.test.js +169 -0
- package/clis/twitter/list-remove.js +13 -6
- package/clis/twitter/list-remove.test.js +74 -0
- package/clis/twitter/list-tweets.js +6 -2
- package/clis/twitter/list-tweets.test.js +41 -1
- package/clis/twitter/lists.js +31 -4
- package/clis/twitter/lists.test.js +152 -16
- package/clis/twitter/notifications.js +4 -4
- package/clis/twitter/post.js +62 -4
- package/clis/twitter/post.test.js +35 -3
- package/clis/twitter/profile.js +81 -28
- package/clis/twitter/profile.test.js +113 -2
- package/clis/twitter/quote.js +9 -4
- package/clis/twitter/reply.js +13 -10
- package/clis/twitter/reply.test.js +41 -0
- package/clis/twitter/search.js +7 -3
- package/clis/twitter/search.test.js +41 -0
- package/clis/twitter/shared.js +155 -0
- package/clis/twitter/shared.test.js +465 -1
- package/clis/twitter/thread.js +10 -2
- package/clis/twitter/thread.test.js +58 -0
- package/clis/twitter/timeline.js +6 -2
- package/clis/twitter/timeline.test.js +2 -0
- package/clis/twitter/tweets.js +3 -2
- package/clis/twitter/tweets.test.js +1 -1
- package/clis/twitter/utils.js +53 -16
- package/clis/upwork/detail.js +132 -0
- package/clis/upwork/feed.js +109 -0
- package/clis/upwork/search.js +115 -0
- package/clis/upwork/upwork.test.js +566 -0
- package/clis/upwork/utils.js +323 -0
- package/clis/weibo/delete.js +172 -0
- package/clis/weibo/delete.test.js +94 -0
- package/clis/weibo/publish.js +37 -14
- package/clis/weibo/publish.test.js +14 -5
- package/clis/weibo/user-posts.js +234 -0
- package/clis/weibo/user-posts.test.js +92 -0
- package/clis/weread/book-search.js +438 -0
- package/clis/weread/book-search.test.js +242 -0
- package/clis/weread/search-regression.test.js +98 -11
- package/clis/weread/search.js +32 -9
- package/clis/weread-official/book.js +135 -0
- package/clis/weread-official/commands.test.js +385 -0
- package/clis/weread-official/discover.js +107 -0
- package/clis/weread-official/list-apis.js +95 -0
- package/clis/weread-official/notes.js +171 -0
- package/clis/weread-official/readdata.js +158 -0
- package/clis/weread-official/review.js +93 -0
- package/clis/weread-official/search.js +106 -0
- package/clis/weread-official/shelf.js +97 -0
- package/clis/weread-official/utils.js +293 -0
- package/clis/weread-official/utils.test.js +242 -0
- package/clis/wikipedia/trending.js +7 -3
- package/clis/wikipedia/trending.test.js +57 -0
- package/clis/xianyu/chat.js +24 -109
- package/clis/xianyu/chat.test.js +5 -0
- package/clis/xianyu/im.js +322 -0
- package/clis/xianyu/im.test.js +253 -0
- package/clis/xianyu/inbox.js +96 -0
- package/clis/xianyu/messages.js +91 -0
- package/clis/xianyu/reply.js +82 -0
- package/clis/xiaohongshu/creator-note-detail.js +166 -28
- package/clis/xiaohongshu/creator-note-detail.test.js +196 -36
- package/clis/xiaohongshu/creator-notes-summary.js +2 -1
- package/clis/xiaohongshu/creator-notes-summary.test.js +7 -0
- package/clis/xiaohongshu/creator-notes.js +252 -2
- package/clis/xiaohongshu/creator-notes.test.js +90 -1
- package/clis/xiaohongshu/creator-stats.js +2 -1
- package/clis/xiaohongshu/creator-stats.test.js +24 -0
- package/clis/xiaohongshu/delete-note.js +260 -0
- package/clis/xiaohongshu/delete-note.test.js +172 -0
- package/clis/xiaohongshu/download.js +97 -39
- package/clis/xiaohongshu/download.test.js +201 -0
- package/clis/xiaohongshu/publish.js +48 -8
- package/clis/xiaohongshu/publish.test.js +65 -10
- package/clis/xiaohongshu/user-helpers.test.js +41 -0
- package/clis/xiaohongshu/user.js +27 -4
- package/clis/xiaoyuzhou/download.js +1 -1
- package/clis/xiaoyuzhou/transcript.js +1 -1
- package/clis/youdao/note.js +258 -0
- package/clis/youdao/note.test.js +99 -0
- package/clis/youtube/transcript.js +397 -24
- package/clis/youtube/transcript.test.js +196 -6
- package/clis/zhihu/answer-comments.js +280 -0
- package/clis/zhihu/answer-comments.test.js +287 -0
- package/clis/zhihu/answer-detail.js +2 -19
- package/clis/zhihu/answer-detail.test.js +8 -0
- package/clis/zhihu/collection.js +17 -16
- package/clis/zhihu/collection.test.js +50 -3
- package/clis/zhihu/download.js +1 -1
- package/clis/zhihu/question.js +42 -17
- package/clis/zhihu/question.test.js +113 -11
- package/clis/zhihu/search.js +195 -43
- package/clis/zhihu/search.test.js +198 -0
- package/clis/zhihu/text.js +29 -0
- package/clis/zhihu/text.test.js +24 -0
- package/dist/src/browser/errors.js +4 -2
- package/dist/src/browser/errors.test.js +6 -0
- package/dist/src/browser/network-cache.js +13 -1
- package/dist/src/browser/network-cache.test.js +17 -0
- package/dist/src/browser/page.js +30 -4
- package/dist/src/browser/page.test.js +42 -0
- package/dist/src/browser/utils.d.ts +1 -1
- package/dist/src/cli-argv-preprocess.d.ts +26 -0
- package/dist/src/cli-argv-preprocess.js +138 -0
- package/dist/src/cli-argv-preprocess.test.js +79 -0
- package/dist/src/convention-audit.js +15 -8
- package/dist/src/convention-audit.test.js +21 -0
- package/dist/src/download/index.js +13 -1
- package/dist/src/download/index.test.js +23 -1
- package/dist/src/download/media-download.js +15 -2
- package/dist/src/download/media-download.test.d.ts +1 -0
- package/dist/src/download/media-download.test.js +112 -0
- package/dist/src/download/progress.js +2 -2
- package/dist/src/download/progress.test.js +12 -1
- package/dist/src/electron-apps.js +1 -1
- package/dist/src/electron-apps.test.js +7 -2
- package/dist/src/errors.d.ts +17 -0
- package/dist/src/errors.js +22 -0
- package/dist/src/external-clis.yaml +8 -0
- package/dist/src/main.js +14 -2
- package/dist/src/output.js +11 -1
- package/dist/src/output.test.js +6 -0
- package/dist/src/registry.js +1 -0
- package/dist/src/registry.test.js +11 -0
- package/dist/src/utils.d.ts +43 -0
- package/dist/src/utils.js +97 -0
- package/dist/src/utils.test.d.ts +1 -0
- package/dist/src/utils.test.js +155 -0
- package/package.json +8 -2
- package/scripts/silent-column-drop-baseline.json +0 -52
- package/scripts/typed-error-lint-baseline.json +28 -380
- package/clis/slock/_utils.js +0 -12
|
@@ -3,7 +3,27 @@ import { JSDOM } from 'jsdom';
|
|
|
3
3
|
import { __test__ } from './shared.js';
|
|
4
4
|
import { ArgumentError } from '@jackwener/opencli/errors';
|
|
5
5
|
|
|
6
|
-
const { extractMedia, parseTweetUrl, buildTwitterArticleScopeSource, unwrapBrowserResult, normalizeTwitterGraphqlPayload, normalizeTwitterScreenName, sanitizeTwitterOperationMetadata } = __test__;
|
|
6
|
+
const { extractMedia, extractCard, extractQuotedTweet, parseTweetUrl, buildTwitterArticleScopeSource, unwrapBrowserResult, normalizeTwitterGraphqlPayload, normalizeTwitterScreenName, sanitizeTwitterOperationMetadata, looksLikePrivateTwitterTimeline } = __test__;
|
|
7
|
+
|
|
8
|
+
function makeCardTweet({ name, bindings, expandedUrl, urls }) {
|
|
9
|
+
const tweet = {
|
|
10
|
+
card: { legacy: { name, binding_values: bindings } },
|
|
11
|
+
};
|
|
12
|
+
if (urls !== undefined) {
|
|
13
|
+
tweet.legacy = { entities: { urls } };
|
|
14
|
+
return tweet;
|
|
15
|
+
}
|
|
16
|
+
if (expandedUrl !== undefined) {
|
|
17
|
+
tweet.legacy = { entities: { urls: [{ expanded_url: expandedUrl }] } };
|
|
18
|
+
}
|
|
19
|
+
return tweet;
|
|
20
|
+
}
|
|
21
|
+
function strBinding(key, string_value) {
|
|
22
|
+
return { key, value: { type: 'STRING', string_value } };
|
|
23
|
+
}
|
|
24
|
+
function imgBinding(key, url) {
|
|
25
|
+
return { key, value: { type: 'IMAGE', image_value: { url } } };
|
|
26
|
+
}
|
|
7
27
|
|
|
8
28
|
describe('twitter browser result helpers', () => {
|
|
9
29
|
it('unwraps Browser Bridge exec envelopes', () => {
|
|
@@ -328,3 +348,447 @@ describe('twitter extractMedia', () => {
|
|
|
328
348
|
});
|
|
329
349
|
});
|
|
330
350
|
});
|
|
351
|
+
|
|
352
|
+
describe('twitter extractCard', () => {
|
|
353
|
+
it('returns null when tweet has no card', () => {
|
|
354
|
+
expect(extractCard({})).toBeNull();
|
|
355
|
+
expect(extractCard(undefined)).toBeNull();
|
|
356
|
+
expect(extractCard({ legacy: { full_text: 'hi' } })).toBeNull();
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('extracts full summary_large_image card with all bindings present', () => {
|
|
360
|
+
const tweet = makeCardTweet({
|
|
361
|
+
name: 'summary_large_image',
|
|
362
|
+
bindings: [
|
|
363
|
+
strBinding('title', 'jackwener/OpenCLI'),
|
|
364
|
+
strBinding('description', 'Make Any Website & Tool Your CLI'),
|
|
365
|
+
strBinding('domain', 'github.com'),
|
|
366
|
+
strBinding('card_url', 'https://t.co/abc'),
|
|
367
|
+
imgBinding('thumbnail_image_large', 'https://pbs.twimg.com/card_img/thumb_large.jpg'),
|
|
368
|
+
imgBinding('photo_image_full_size_large', 'https://pbs.twimg.com/card_img/photo_large.jpg'),
|
|
369
|
+
imgBinding('summary_photo_image_large', 'https://pbs.twimg.com/card_img/summary_large.jpg'),
|
|
370
|
+
],
|
|
371
|
+
urls: [{ url: 'https://t.co/abc', expanded_url: 'https://github.com/jackwener/OpenCLI' }],
|
|
372
|
+
});
|
|
373
|
+
expect(extractCard(tweet)).toEqual({
|
|
374
|
+
name: 'summary_large_image',
|
|
375
|
+
title: 'jackwener/OpenCLI',
|
|
376
|
+
description: 'Make Any Website & Tool Your CLI',
|
|
377
|
+
image_url: 'https://pbs.twimg.com/card_img/thumb_large.jpg',
|
|
378
|
+
url: 'https://github.com/jackwener/OpenCLI',
|
|
379
|
+
domain: 'github.com',
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('picks summary_photo_image_large when higher-priority image keys are missing', () => {
|
|
384
|
+
const tweet = makeCardTweet({
|
|
385
|
+
name: 'summary',
|
|
386
|
+
bindings: [
|
|
387
|
+
strBinding('title', 'Some article'),
|
|
388
|
+
strBinding('description', 'Body text'),
|
|
389
|
+
strBinding('domain', 'example.com'),
|
|
390
|
+
imgBinding('summary_photo_image_large', 'https://pbs.twimg.com/card_img/fallback.jpg'),
|
|
391
|
+
],
|
|
392
|
+
expandedUrl: 'https://example.com/article',
|
|
393
|
+
});
|
|
394
|
+
const card = extractCard(tweet);
|
|
395
|
+
expect(card.image_url).toBe('https://pbs.twimg.com/card_img/fallback.jpg');
|
|
396
|
+
expect(card.name).toBe('summary');
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('derives domain from expanded_url when domain binding is missing', () => {
|
|
400
|
+
const tweet = makeCardTweet({
|
|
401
|
+
name: 'promo_image_convo',
|
|
402
|
+
bindings: [
|
|
403
|
+
strBinding('title', 'YouTube video'),
|
|
404
|
+
strBinding('card_url', 'https://t.co/youtube'),
|
|
405
|
+
imgBinding('photo_image_full_size_large', 'https://pbs.twimg.com/card_img/yt.jpg'),
|
|
406
|
+
],
|
|
407
|
+
urls: [{ url: 'https://t.co/youtube', expanded_url: 'https://www.youtube.com/watch?v=abc' }],
|
|
408
|
+
});
|
|
409
|
+
const card = extractCard(tweet);
|
|
410
|
+
expect(card.url).toBe('https://www.youtube.com/watch?v=abc');
|
|
411
|
+
expect(card.domain).toBe('www.youtube.com');
|
|
412
|
+
expect(card.image_url).toBe('https://pbs.twimg.com/card_img/yt.jpg');
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it('falls back to card_url binding when there is no expanded_url', () => {
|
|
416
|
+
const tweet = makeCardTweet({
|
|
417
|
+
name: 'summary_large_image',
|
|
418
|
+
bindings: [
|
|
419
|
+
strBinding('title', 'arXiv paper'),
|
|
420
|
+
strBinding('card_url', 'https://arxiv.org/abs/2305.12345'),
|
|
421
|
+
],
|
|
422
|
+
expandedUrl: undefined,
|
|
423
|
+
});
|
|
424
|
+
const card = extractCard(tweet);
|
|
425
|
+
expect(card.url).toBe('https://arxiv.org/abs/2305.12345');
|
|
426
|
+
expect(card.domain).toBe('arxiv.org');
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it('matches card_url to the correct URL entity instead of assuming the first tweet URL', () => {
|
|
430
|
+
const tweet = makeCardTweet({
|
|
431
|
+
name: 'summary_large_image',
|
|
432
|
+
bindings: [
|
|
433
|
+
strBinding('title', 'OpenCLI release'),
|
|
434
|
+
strBinding('card_url', 'https://t.co/card123'),
|
|
435
|
+
],
|
|
436
|
+
urls: [
|
|
437
|
+
{ url: 'https://t.co/unrelated', expanded_url: 'https://example.com/unrelated' },
|
|
438
|
+
{ url: 'https://t.co/card123', expanded_url: 'https://github.com/jackwener/OpenCLI/releases' },
|
|
439
|
+
],
|
|
440
|
+
});
|
|
441
|
+
const card = extractCard(tweet);
|
|
442
|
+
expect(card.url).toBe('https://github.com/jackwener/OpenCLI/releases');
|
|
443
|
+
expect(card.domain).toBe('github.com');
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('falls back to card_url itself when no matching URL entity is present', () => {
|
|
447
|
+
const tweet = makeCardTweet({
|
|
448
|
+
name: 'summary_large_image',
|
|
449
|
+
bindings: [
|
|
450
|
+
strBinding('title', 'Unmatched card'),
|
|
451
|
+
strBinding('card_url', 'https://t.co/card123'),
|
|
452
|
+
],
|
|
453
|
+
urls: [
|
|
454
|
+
{ url: 'https://t.co/unrelated', expanded_url: 'https://example.com/unrelated' },
|
|
455
|
+
],
|
|
456
|
+
});
|
|
457
|
+
const card = extractCard(tweet);
|
|
458
|
+
expect(card.url).toBe('https://t.co/card123');
|
|
459
|
+
expect(card.domain).toBe('t.co');
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
it('omits missing fields rather than emitting undefined values', () => {
|
|
463
|
+
const tweet = makeCardTweet({
|
|
464
|
+
name: 'summary',
|
|
465
|
+
bindings: [
|
|
466
|
+
strBinding('title', 'Just a title'),
|
|
467
|
+
strBinding('description', 'Just a description'),
|
|
468
|
+
strBinding('card_url', 'https://t.co/example'),
|
|
469
|
+
],
|
|
470
|
+
urls: [{ url: 'https://t.co/example', expanded_url: 'https://example.com/x' }],
|
|
471
|
+
});
|
|
472
|
+
const card = extractCard(tweet);
|
|
473
|
+
expect('image_url' in card).toBe(false);
|
|
474
|
+
expect(card).toEqual({
|
|
475
|
+
name: 'summary',
|
|
476
|
+
title: 'Just a title',
|
|
477
|
+
description: 'Just a description',
|
|
478
|
+
url: 'https://example.com/x',
|
|
479
|
+
domain: 'example.com',
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('returns null for a structurally empty card (no url, no title, no description)', () => {
|
|
484
|
+
const tweet = makeCardTweet({
|
|
485
|
+
name: 'summary',
|
|
486
|
+
bindings: [
|
|
487
|
+
imgBinding('thumbnail_image_large', 'https://pbs.twimg.com/card_img/x.jpg'),
|
|
488
|
+
],
|
|
489
|
+
expandedUrl: undefined,
|
|
490
|
+
});
|
|
491
|
+
expect(extractCard(tweet)).toBeNull();
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it('does not throw on a malformed expanded_url; domain is simply omitted', () => {
|
|
495
|
+
const tweet = makeCardTweet({
|
|
496
|
+
name: 'summary',
|
|
497
|
+
bindings: [
|
|
498
|
+
strBinding('title', 'broken url card'),
|
|
499
|
+
strBinding('card_url', 'https://t.co/broken'),
|
|
500
|
+
],
|
|
501
|
+
urls: [{ url: 'https://t.co/broken', expanded_url: 'not a url' }],
|
|
502
|
+
});
|
|
503
|
+
const card = extractCard(tweet);
|
|
504
|
+
expect(card.url).toBe('not a url');
|
|
505
|
+
expect('domain' in card).toBe(false);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it('tolerates missing binding_values array', () => {
|
|
509
|
+
const tweet = {
|
|
510
|
+
card: { legacy: { name: 'summary' } },
|
|
511
|
+
legacy: { entities: { urls: [{ expanded_url: 'https://example.com/' }] } },
|
|
512
|
+
};
|
|
513
|
+
const card = extractCard(tweet);
|
|
514
|
+
expect(card).toBeNull();
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
describe('twitter extractQuotedTweet', () => {
|
|
519
|
+
it('returns null on plain tweets (is_quote_status absent or false)', () => {
|
|
520
|
+
expect(extractQuotedTweet({})).toBeNull();
|
|
521
|
+
expect(extractQuotedTweet({ legacy: {} })).toBeNull();
|
|
522
|
+
expect(extractQuotedTweet({ legacy: { is_quote_status: false } })).toBeNull();
|
|
523
|
+
// is_quote_status true but no nested result (deleted / restricted): still null
|
|
524
|
+
expect(extractQuotedTweet({
|
|
525
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '99' },
|
|
526
|
+
})).toBeNull();
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
it('returns null on tombstoned / unavailable quoted tweets', () => {
|
|
530
|
+
// GraphQL emits TweetTombstone / TweetUnavailable when the quoted tweet
|
|
531
|
+
// is deleted, suspended, or privacy-restricted. The wrapper has no
|
|
532
|
+
// `legacy` / `rest_id` — null-coalesces in the helper cover this.
|
|
533
|
+
const tweet = {
|
|
534
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '99' },
|
|
535
|
+
quoted_status_result: { result: { __typename: 'TweetTombstone' } },
|
|
536
|
+
};
|
|
537
|
+
expect(extractQuotedTweet(tweet)).toBeNull();
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it('returns null when the quoted tweet lacks author identity', () => {
|
|
541
|
+
const tweet = {
|
|
542
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '99' },
|
|
543
|
+
quoted_status_result: {
|
|
544
|
+
result: {
|
|
545
|
+
rest_id: '99',
|
|
546
|
+
legacy: { full_text: 'real quoted text' },
|
|
547
|
+
core: { user_results: { result: { legacy: {} } } },
|
|
548
|
+
},
|
|
549
|
+
},
|
|
550
|
+
};
|
|
551
|
+
expect(extractQuotedTweet(tweet)).toBeNull();
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
it('returns null when the quoted tweet author identity has the wrong shape', () => {
|
|
555
|
+
const tweet = {
|
|
556
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '99' },
|
|
557
|
+
quoted_status_result: {
|
|
558
|
+
result: {
|
|
559
|
+
rest_id: '99',
|
|
560
|
+
legacy: { full_text: 'real quoted text' },
|
|
561
|
+
core: {
|
|
562
|
+
user_results: {
|
|
563
|
+
result: {
|
|
564
|
+
legacy: { screen_name: { value: 'alice' }, name: { value: 'Alice' } },
|
|
565
|
+
},
|
|
566
|
+
},
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
},
|
|
570
|
+
};
|
|
571
|
+
expect(extractQuotedTweet(tweet)).toBeNull();
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it('returns null when the quoted tweet author handle is not a valid screen name', () => {
|
|
575
|
+
const tweet = {
|
|
576
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '99' },
|
|
577
|
+
quoted_status_result: {
|
|
578
|
+
result: {
|
|
579
|
+
rest_id: '99',
|
|
580
|
+
legacy: { full_text: 'real quoted text' },
|
|
581
|
+
core: { user_results: { result: { legacy: { screen_name: 'not/a/user' } } } },
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
};
|
|
585
|
+
expect(extractQuotedTweet(tweet)).toBeNull();
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
it('returns null when the quoted tweet lacks renderable content', () => {
|
|
589
|
+
const tweet = {
|
|
590
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '99' },
|
|
591
|
+
quoted_status_result: {
|
|
592
|
+
result: {
|
|
593
|
+
rest_id: '99',
|
|
594
|
+
legacy: {},
|
|
595
|
+
core: { user_results: { result: { legacy: { screen_name: 'alice' } } } },
|
|
596
|
+
},
|
|
597
|
+
},
|
|
598
|
+
};
|
|
599
|
+
expect(extractQuotedTweet(tweet)).toBeNull();
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
it('extracts a minimal quoted tweet shape with author, text, url', () => {
|
|
603
|
+
const tweet = {
|
|
604
|
+
legacy: { is_quote_status: true, quoted_status_id_str: '2040254679301718161' },
|
|
605
|
+
quoted_status_result: {
|
|
606
|
+
result: {
|
|
607
|
+
rest_id: '2040254679301718161',
|
|
608
|
+
legacy: {
|
|
609
|
+
full_text: '罗某官二代背景考',
|
|
610
|
+
created_at: 'Wed May 13 22:00:00 +0000 2026',
|
|
611
|
+
},
|
|
612
|
+
core: {
|
|
613
|
+
user_results: {
|
|
614
|
+
result: { legacy: { screen_name: 'alice', name: 'Alice' } },
|
|
615
|
+
},
|
|
616
|
+
},
|
|
617
|
+
},
|
|
618
|
+
},
|
|
619
|
+
};
|
|
620
|
+
expect(extractQuotedTweet(tweet)).toEqual({
|
|
621
|
+
id: '2040254679301718161',
|
|
622
|
+
author: 'alice',
|
|
623
|
+
name: 'Alice',
|
|
624
|
+
text: '罗某官二代背景考',
|
|
625
|
+
created_at: 'Wed May 13 22:00:00 +0000 2026',
|
|
626
|
+
url: 'https://x.com/alice/status/2040254679301718161',
|
|
627
|
+
has_media: false,
|
|
628
|
+
media_urls: [],
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
it('extracts media from the quoted tweet via extractMedia', () => {
|
|
633
|
+
const tweet = {
|
|
634
|
+
legacy: { is_quote_status: true },
|
|
635
|
+
quoted_status_result: {
|
|
636
|
+
result: {
|
|
637
|
+
rest_id: '99',
|
|
638
|
+
legacy: {
|
|
639
|
+
full_text: '日本电车实录',
|
|
640
|
+
extended_entities: {
|
|
641
|
+
media: [
|
|
642
|
+
{ type: 'photo', media_url_https: 'https://pbs.twimg.com/media/a.jpg' },
|
|
643
|
+
{ type: 'photo', media_url_https: 'https://pbs.twimg.com/media/b.jpg' },
|
|
644
|
+
],
|
|
645
|
+
},
|
|
646
|
+
},
|
|
647
|
+
core: { user_results: { result: { legacy: { screen_name: 'rwayne' } } } },
|
|
648
|
+
},
|
|
649
|
+
},
|
|
650
|
+
};
|
|
651
|
+
const q = extractQuotedTweet(tweet);
|
|
652
|
+
expect(q.has_media).toBe(true);
|
|
653
|
+
expect(q.media_urls).toEqual([
|
|
654
|
+
'https://pbs.twimg.com/media/a.jpg',
|
|
655
|
+
'https://pbs.twimg.com/media/b.jpg',
|
|
656
|
+
]);
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it('extracts the quoted tweet card when present', () => {
|
|
660
|
+
const tweet = {
|
|
661
|
+
legacy: { is_quote_status: true },
|
|
662
|
+
quoted_status_result: {
|
|
663
|
+
result: {
|
|
664
|
+
rest_id: '100',
|
|
665
|
+
legacy: {
|
|
666
|
+
full_text: '',
|
|
667
|
+
entities: {
|
|
668
|
+
urls: [{ url: 'https://t.co/abc', expanded_url: 'https://github.com/x/y' }],
|
|
669
|
+
},
|
|
670
|
+
},
|
|
671
|
+
core: { user_results: { result: { legacy: { screen_name: 'bob' } } } },
|
|
672
|
+
card: {
|
|
673
|
+
legacy: {
|
|
674
|
+
name: 'summary_large_image',
|
|
675
|
+
binding_values: [
|
|
676
|
+
{ key: 'title', value: { type: 'STRING', string_value: 'x/y' } },
|
|
677
|
+
{ key: 'card_url', value: { type: 'STRING', string_value: 'https://t.co/abc' } },
|
|
678
|
+
],
|
|
679
|
+
},
|
|
680
|
+
},
|
|
681
|
+
},
|
|
682
|
+
},
|
|
683
|
+
};
|
|
684
|
+
const q = extractQuotedTweet(tweet);
|
|
685
|
+
expect(q.card).toEqual({
|
|
686
|
+
name: 'summary_large_image',
|
|
687
|
+
title: 'x/y',
|
|
688
|
+
url: 'https://github.com/x/y',
|
|
689
|
+
domain: 'github.com',
|
|
690
|
+
});
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
it('prefers long-form note_tweet text over truncated legacy full_text', () => {
|
|
694
|
+
const tweet = {
|
|
695
|
+
legacy: { is_quote_status: true },
|
|
696
|
+
quoted_status_result: {
|
|
697
|
+
result: {
|
|
698
|
+
rest_id: '101',
|
|
699
|
+
legacy: { full_text: 'short…' },
|
|
700
|
+
note_tweet: { note_tweet_results: { result: { text: 'full long body of the quoted tweet' } } },
|
|
701
|
+
core: { user_results: { result: { legacy: { screen_name: 'carol' } } } },
|
|
702
|
+
},
|
|
703
|
+
},
|
|
704
|
+
};
|
|
705
|
+
expect(extractQuotedTweet(tweet)?.text).toBe('full long body of the quoted tweet');
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
it('unwraps TweetWithVisibilityResults — quoted_status_result.result.tweet shim', () => {
|
|
709
|
+
// Mirrors the top-level `tw.tweet || tw` shim that callers do for sensitive content.
|
|
710
|
+
const tweet = {
|
|
711
|
+
legacy: { is_quote_status: true },
|
|
712
|
+
quoted_status_result: {
|
|
713
|
+
result: {
|
|
714
|
+
__typename: 'TweetWithVisibilityResults',
|
|
715
|
+
tweet: {
|
|
716
|
+
rest_id: '102',
|
|
717
|
+
legacy: { full_text: 'sensitive content quoted' },
|
|
718
|
+
core: { user_results: { result: { legacy: { screen_name: 'dave' } } } },
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
},
|
|
722
|
+
};
|
|
723
|
+
const q = extractQuotedTweet(tweet);
|
|
724
|
+
expect(q?.id).toBe('102');
|
|
725
|
+
expect(q?.author).toBe('dave');
|
|
726
|
+
expect(q?.text).toBe('sensitive content quoted');
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
it('does NOT recurse — a quote of a quote drops the inner-inner quote', () => {
|
|
730
|
+
// Avoid payload explosion on threads where every reply re-quotes the root.
|
|
731
|
+
// Level-1 quote is preserved; level-2 (a quote inside the quoted tweet)
|
|
732
|
+
// is intentionally not surfaced.
|
|
733
|
+
const tweet = {
|
|
734
|
+
legacy: { is_quote_status: true },
|
|
735
|
+
quoted_status_result: {
|
|
736
|
+
result: {
|
|
737
|
+
rest_id: '200',
|
|
738
|
+
legacy: {
|
|
739
|
+
full_text: 'level-1 quote text',
|
|
740
|
+
is_quote_status: true,
|
|
741
|
+
},
|
|
742
|
+
core: { user_results: { result: { legacy: { screen_name: 'l1' } } } },
|
|
743
|
+
quoted_status_result: {
|
|
744
|
+
result: {
|
|
745
|
+
rest_id: '300',
|
|
746
|
+
legacy: { full_text: 'level-2 should be dropped' },
|
|
747
|
+
core: { user_results: { result: { legacy: { screen_name: 'l2' } } } },
|
|
748
|
+
},
|
|
749
|
+
},
|
|
750
|
+
},
|
|
751
|
+
},
|
|
752
|
+
};
|
|
753
|
+
const q = extractQuotedTweet(tweet);
|
|
754
|
+
expect(q?.id).toBe('200');
|
|
755
|
+
expect(q?.text).toBe('level-1 quote text');
|
|
756
|
+
expect(q).not.toHaveProperty('quoted_tweet');
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
describe('looksLikePrivateTwitterTimeline', () => {
|
|
761
|
+
it('returns true when result.timeline is an empty object', () => {
|
|
762
|
+
expect(looksLikePrivateTwitterTimeline({
|
|
763
|
+
data: { user: { result: { __typename: 'User', timeline: {} } } },
|
|
764
|
+
})).toBe(true);
|
|
765
|
+
});
|
|
766
|
+
it('returns false when timeline.timeline.instructions is present', () => {
|
|
767
|
+
expect(looksLikePrivateTwitterTimeline({
|
|
768
|
+
data: { user: { result: { timeline: { timeline: { instructions: [] } } } } },
|
|
769
|
+
})).toBe(false);
|
|
770
|
+
});
|
|
771
|
+
it('returns false when timeline_v2.timeline.instructions is present', () => {
|
|
772
|
+
expect(looksLikePrivateTwitterTimeline({
|
|
773
|
+
data: { user: { result: { timeline_v2: { timeline: { instructions: [] } } } } },
|
|
774
|
+
})).toBe(false);
|
|
775
|
+
});
|
|
776
|
+
it('returns false when result is missing entirely', () => {
|
|
777
|
+
expect(looksLikePrivateTwitterTimeline({})).toBe(false);
|
|
778
|
+
expect(looksLikePrivateTwitterTimeline(null)).toBe(false);
|
|
779
|
+
expect(looksLikePrivateTwitterTimeline({ data: { user: {} } })).toBe(false);
|
|
780
|
+
});
|
|
781
|
+
it('returns false for non-empty malformed timeline objects', () => {
|
|
782
|
+
expect(looksLikePrivateTwitterTimeline({
|
|
783
|
+
data: { user: { result: { timeline: { unexpected: true } } } },
|
|
784
|
+
})).toBe(false);
|
|
785
|
+
expect(looksLikePrivateTwitterTimeline({
|
|
786
|
+
data: { user: { result: { timeline: { timeline: {} } } } },
|
|
787
|
+
})).toBe(false);
|
|
788
|
+
});
|
|
789
|
+
it('returns true when timeline_v2.timeline is an empty object', () => {
|
|
790
|
+
expect(looksLikePrivateTwitterTimeline({
|
|
791
|
+
data: { user: { result: { timeline_v2: { timeline: {} } } } },
|
|
792
|
+
})).toBe(true);
|
|
793
|
+
});
|
|
794
|
+
});
|
package/clis/twitter/thread.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
2
2
|
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
|
|
3
|
-
import { extractMedia } from './shared.js';
|
|
3
|
+
import { extractMedia, extractCard, extractQuotedTweet } from './shared.js';
|
|
4
4
|
import { TWITTER_BEARER_TOKEN, applyTopByEngagement } from './utils.js';
|
|
5
5
|
// ── Twitter GraphQL constants ──────────────────────────────────────────
|
|
6
6
|
const TWEET_DETAIL_QUERY_ID = 'nBS-WpgA6ZG0CyNHD517JQ';
|
|
@@ -46,9 +46,11 @@ function extractTweet(r, seen) {
|
|
|
46
46
|
const u = tw.core?.user_results?.result;
|
|
47
47
|
const noteText = tw.note_tweet?.note_tweet_results?.result?.text;
|
|
48
48
|
const screenName = u?.legacy?.screen_name || u?.core?.screen_name || 'unknown';
|
|
49
|
+
const bio = u?.legacy?.description || '';
|
|
49
50
|
return {
|
|
50
51
|
id: tw.rest_id,
|
|
51
52
|
author: screenName,
|
|
53
|
+
bio,
|
|
52
54
|
text: noteText || l.full_text || '',
|
|
53
55
|
likes: l.favorite_count || 0,
|
|
54
56
|
retweets: l.retweet_count || 0,
|
|
@@ -56,6 +58,8 @@ function extractTweet(r, seen) {
|
|
|
56
58
|
created_at: l.created_at,
|
|
57
59
|
url: `https://x.com/${screenName}/status/${tw.rest_id}`,
|
|
58
60
|
...extractMedia(l),
|
|
61
|
+
card: extractCard(tw),
|
|
62
|
+
quoted_tweet: extractQuotedTweet(tw),
|
|
59
63
|
};
|
|
60
64
|
}
|
|
61
65
|
function parseTweetDetail(data, seen) {
|
|
@@ -91,6 +95,10 @@ function parseTweetDetail(data, seen) {
|
|
|
91
95
|
}
|
|
92
96
|
return { tweets, nextCursor };
|
|
93
97
|
}
|
|
98
|
+
|
|
99
|
+
export const __test__ = {
|
|
100
|
+
parseTweetDetail,
|
|
101
|
+
};
|
|
94
102
|
// ── CLI definition ────────────────────────────────────────────────────
|
|
95
103
|
cli({
|
|
96
104
|
site: 'twitter',
|
|
@@ -105,7 +113,7 @@ cli({
|
|
|
105
113
|
{ name: 'limit', type: 'int', default: 50 },
|
|
106
114
|
{ name: 'top-by-engagement', type: 'int', default: 0, help: 'When set to N>0, re-rank the thread by weighted engagement (likes×1 + retweets×3 + replies×2 + bookmarks×5 + log10(views+1)×0.5) and return the top N. Default 0 keeps the conversation\'s structural ordering.' },
|
|
107
115
|
],
|
|
108
|
-
columns: ['id', 'author', 'text', 'likes', 'retweets', 'url', 'has_media', 'media_urls'],
|
|
116
|
+
columns: ['id', 'author', 'bio', 'text', 'likes', 'retweets', 'url', 'has_media', 'media_urls', 'card', 'quoted_tweet'],
|
|
109
117
|
func: async (page, kwargs) => {
|
|
110
118
|
let tweetId = kwargs['tweet-id'];
|
|
111
119
|
const urlMatch = tweetId.match(/\/status\/(\d+)/);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getRegistry } from '@jackwener/opencli/registry';
|
|
3
|
+
import { __test__ } from './thread.js';
|
|
4
|
+
|
|
5
|
+
describe('twitter thread parser', () => {
|
|
6
|
+
it('extracts author bio from tweet user entity', () => {
|
|
7
|
+
const command = getRegistry().get('twitter/thread');
|
|
8
|
+
expect(command?.columns).toEqual(['id', 'author', 'bio', 'text', 'likes', 'retweets', 'url', 'has_media', 'media_urls', 'card', 'quoted_tweet']);
|
|
9
|
+
const result = __test__.parseTweetDetail({
|
|
10
|
+
data: {
|
|
11
|
+
threaded_conversation_with_injections_v2: {
|
|
12
|
+
instructions: [
|
|
13
|
+
{
|
|
14
|
+
entries: [
|
|
15
|
+
{
|
|
16
|
+
content: {
|
|
17
|
+
itemContent: {
|
|
18
|
+
tweet_results: {
|
|
19
|
+
result: {
|
|
20
|
+
rest_id: '1',
|
|
21
|
+
legacy: {
|
|
22
|
+
full_text: 'thread tweet',
|
|
23
|
+
favorite_count: 3,
|
|
24
|
+
retweet_count: 2,
|
|
25
|
+
},
|
|
26
|
+
core: {
|
|
27
|
+
user_results: {
|
|
28
|
+
result: {
|
|
29
|
+
legacy: {
|
|
30
|
+
screen_name: 'alice',
|
|
31
|
+
description: 'Thread author bio',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}, new Set());
|
|
47
|
+
expect(result.tweets).toHaveLength(1);
|
|
48
|
+
expect(result.tweets[0]).toMatchObject({
|
|
49
|
+
id: '1',
|
|
50
|
+
author: 'alice',
|
|
51
|
+
bio: 'Thread author bio',
|
|
52
|
+
text: 'thread tweet',
|
|
53
|
+
likes: 3,
|
|
54
|
+
retweets: 2,
|
|
55
|
+
url: 'https://x.com/alice/status/1',
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
package/clis/twitter/timeline.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
|
|
2
2
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
3
|
-
import { resolveTwitterQueryId, extractMedia } from './shared.js';
|
|
3
|
+
import { resolveTwitterQueryId, extractMedia, extractCard, extractQuotedTweet } from './shared.js';
|
|
4
4
|
import { TWITTER_BEARER_TOKEN, applyTopByEngagement } from './utils.js';
|
|
5
5
|
// ── Twitter GraphQL constants ──────────────────────────────────────────
|
|
6
6
|
const HOME_TIMELINE_QUERY_ID = 'c-CzHF1LboFilMpsx4ZCrQ';
|
|
@@ -74,11 +74,13 @@ function extractTweet(result, seen) {
|
|
|
74
74
|
seen.add(tw.rest_id);
|
|
75
75
|
const u = tw.core?.user_results?.result;
|
|
76
76
|
const screenName = u?.legacy?.screen_name || u?.core?.screen_name || 'unknown';
|
|
77
|
+
const bio = u?.legacy?.description || '';
|
|
77
78
|
const noteText = tw.note_tweet?.note_tweet_results?.result?.text;
|
|
78
79
|
const views = tw.views?.count ? parseInt(tw.views.count, 10) : 0;
|
|
79
80
|
return {
|
|
80
81
|
id: tw.rest_id,
|
|
81
82
|
author: screenName,
|
|
83
|
+
bio,
|
|
82
84
|
text: noteText || l.full_text || '',
|
|
83
85
|
likes: l.favorite_count || 0,
|
|
84
86
|
retweets: l.retweet_count || 0,
|
|
@@ -87,6 +89,8 @@ function extractTweet(result, seen) {
|
|
|
87
89
|
created_at: l.created_at || '',
|
|
88
90
|
url: `https://x.com/${screenName}/status/${tw.rest_id}`,
|
|
89
91
|
...extractMedia(l),
|
|
92
|
+
card: extractCard(tw),
|
|
93
|
+
quoted_tweet: extractQuotedTweet(tw),
|
|
90
94
|
};
|
|
91
95
|
}
|
|
92
96
|
function parseHomeTimeline(data, seen) {
|
|
@@ -152,7 +156,7 @@ cli({
|
|
|
152
156
|
{ name: 'limit', type: 'int', default: 20, help: 'Maximum number of tweets to return (default 20).' },
|
|
153
157
|
{ name: 'top-by-engagement', type: 'int', default: 0, help: 'When set to N>0, re-rank the timeline by weighted engagement (likes×1 + retweets×3 + replies×2 + bookmarks×5 + log10(views+1)×0.5) and return the top N. Default 0 keeps X\'s native ordering.' },
|
|
154
158
|
],
|
|
155
|
-
columns: ['id', 'author', 'text', 'likes', 'retweets', 'replies', 'views', 'created_at', 'url', 'has_media', 'media_urls'],
|
|
159
|
+
columns: ['id', 'author', 'bio', 'text', 'likes', 'retweets', 'replies', 'views', 'created_at', 'url', 'has_media', 'media_urls', 'card', 'quoted_tweet'],
|
|
156
160
|
func: async (page, kwargs) => {
|
|
157
161
|
const limit = kwargs.limit || 20;
|
|
158
162
|
const timelineType = kwargs.type === 'following' ? 'following' : 'for-you';
|
|
@@ -57,6 +57,7 @@ describe('twitter timeline helpers', () => {
|
|
|
57
57
|
result: {
|
|
58
58
|
legacy: {
|
|
59
59
|
screen_name: 'alice',
|
|
60
|
+
description: 'Timeline author bio',
|
|
60
61
|
},
|
|
61
62
|
},
|
|
62
63
|
},
|
|
@@ -90,6 +91,7 @@ describe('twitter timeline helpers', () => {
|
|
|
90
91
|
expect(result.tweets[0]).toMatchObject({
|
|
91
92
|
id: '1',
|
|
92
93
|
author: 'alice',
|
|
94
|
+
bio: 'Timeline author bio',
|
|
93
95
|
text: 'hello',
|
|
94
96
|
likes: 3,
|
|
95
97
|
retweets: 2,
|
package/clis/twitter/tweets.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
2
2
|
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
|
|
3
|
-
import { resolveTwitterOperationMetadata, sanitizeQueryId, extractMedia, normalizeTwitterGraphqlPayload, unwrapBrowserResult } from './shared.js';
|
|
3
|
+
import { resolveTwitterOperationMetadata, sanitizeQueryId, extractMedia, extractQuotedTweet, normalizeTwitterGraphqlPayload, unwrapBrowserResult } from './shared.js';
|
|
4
4
|
import { normalizeTwitterScreenName } from './shared.js';
|
|
5
5
|
import { TWITTER_BEARER_TOKEN, applyTopByEngagement } from './utils.js';
|
|
6
6
|
|
|
@@ -175,6 +175,7 @@ function extractTweet(result, seen) {
|
|
|
175
175
|
created_at: legacy.created_at || '',
|
|
176
176
|
url: `https://x.com/${screenName}/status/${tw.rest_id}`,
|
|
177
177
|
...extractMedia(legacy),
|
|
178
|
+
quoted_tweet: extractQuotedTweet(tw),
|
|
178
179
|
};
|
|
179
180
|
}
|
|
180
181
|
|
|
@@ -226,7 +227,7 @@ cli({
|
|
|
226
227
|
{ name: 'limit', type: 'int', default: 20, help: 'Max tweets to return' },
|
|
227
228
|
{ name: 'top-by-engagement', type: 'int', default: 0, help: 'When set to N>0, re-rank the tweets by weighted engagement (likes×1 + retweets×3 + replies×2 + bookmarks×5 + log10(views+1)×0.5) and return the top N. Default 0 keeps the chronological ordering.' },
|
|
228
229
|
],
|
|
229
|
-
columns: ['id', 'author', 'created_at', 'is_retweet', 'text', 'likes', 'retweets', 'replies', 'views', 'url', 'has_media', 'media_urls'],
|
|
230
|
+
columns: ['id', 'author', 'created_at', 'is_retweet', 'text', 'likes', 'retweets', 'replies', 'views', 'url', 'has_media', 'media_urls', 'quoted_tweet'],
|
|
230
231
|
func: async (page, kwargs) => {
|
|
231
232
|
const limit = Math.max(1, Math.min(200, kwargs.limit || 20));
|
|
232
233
|
const rawUsername = String(kwargs.username ?? '').trim();
|
|
@@ -6,7 +6,7 @@ import { __test__ } from './tweets.js';
|
|
|
6
6
|
describe('twitter tweets helpers', () => {
|
|
7
7
|
it('registers id and is_retweet in the default columns', () => {
|
|
8
8
|
const cmd = getRegistry().get('twitter/tweets');
|
|
9
|
-
expect(cmd?.columns).toEqual(['id', 'author', 'created_at', 'is_retweet', 'text', 'likes', 'retweets', 'replies', 'views', 'url', 'has_media', 'media_urls']);
|
|
9
|
+
expect(cmd?.columns).toEqual(['id', 'author', 'created_at', 'is_retweet', 'text', 'likes', 'retweets', 'replies', 'views', 'url', 'has_media', 'media_urls', 'quoted_tweet']);
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
it('makes the username argument optional so it can default to the logged-in user', () => {
|