-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathindex.d.ts
More file actions
757 lines (622 loc) · 25.6 KB
/
index.d.ts
File metadata and controls
757 lines (622 loc) · 25.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
// ═══════════════════════════════════════════════════════════════════════════════
// XActions — TypeScript Type Declarations
// The Complete X/Twitter Automation Toolkit
// by nichxbt
// ═══════════════════════════════════════════════════════════════════════════════
import type { Browser, Page } from 'puppeteer';
// ── Core Types ──────────────────────────────────────────────────────────────
export interface BrowserOptions {
headless?: boolean;
proxy?: string;
userDataDir?: string;
args?: string[];
}
export interface ScrapeOptions {
limit?: number;
format?: 'json' | 'csv';
output?: string;
}
// ── Profile ─────────────────────────────────────────────────────────────────
export interface Profile {
name: string;
username: string;
bio: string;
location?: string;
website?: string;
joinDate?: string;
followers: number;
following: number;
tweets: number;
verified: boolean;
avatar?: string;
header?: string;
}
// ── User ────────────────────────────────────────────────────────────────────
export interface User {
name: string;
username: string;
bio?: string;
followers?: number;
following?: number;
verified?: boolean;
followsBack?: boolean;
}
// ── Tweet ───────────────────────────────────────────────────────────────────
export interface Tweet {
id: string;
text: string;
author: string;
authorUsername: string;
timestamp: string;
likes: number;
retweets: number;
replies: number;
views?: number;
url: string;
media?: MediaItem[];
isRetweet?: boolean;
isQuote?: boolean;
quotedTweet?: Tweet;
}
export interface MediaItem {
type: 'image' | 'video' | 'gif';
url: string;
thumbnailUrl?: string;
width?: number;
height?: number;
duration?: number;
}
// ── Thread ──────────────────────────────────────────────────────────────────
export interface Thread {
author: string;
tweets: Tweet[];
totalTweets: number;
text: string;
}
// ── Video ───────────────────────────────────────────────────────────────────
export interface VideoResult {
url: string;
variants: VideoVariant[];
thumbnail?: string;
duration?: number;
}
export interface VideoVariant {
url: string;
bitrate?: number;
contentType: string;
}
// ── Bookmark ────────────────────────────────────────────────────────────────
export interface Bookmark {
tweet: Tweet;
savedAt?: string;
}
// ── DM ──────────────────────────────────────────────────────────────────────
export interface Conversation {
id: string;
participants: User[];
lastMessage: string;
lastMessageTime: string;
unread: boolean;
}
export interface DirectMessage {
id: string;
text: string;
sender: string;
recipient: string;
timestamp: string;
media?: MediaItem[];
}
// ── Analytics ───────────────────────────────────────────────────────────────
export interface Analytics {
followers: number;
following: number;
tweets: number;
impressions?: number;
profileVisits?: number;
mentions?: number;
period?: string;
}
export interface PostAnalytics {
tweet: Tweet;
impressions: number;
engagements: number;
engagementRate: number;
likes: number;
retweets: number;
replies: number;
clicks?: number;
profileClicks?: number;
}
// ── Sentiment ───────────────────────────────────────────────────────────────
export interface SentimentResult {
score: number;
label: 'positive' | 'neutral' | 'negative';
confidence: number;
keywords: string[];
}
// ── Workflow ────────────────────────────────────────────────────────────────
export interface Workflow {
id: string;
name: string;
description?: string;
trigger: WorkflowTrigger;
steps: WorkflowStep[];
enabled: boolean;
createdAt: string;
}
export interface WorkflowTrigger {
type: 'manual' | 'schedule' | 'webhook';
cron?: string;
}
export interface WorkflowStep {
action?: string;
target?: string;
input?: string;
output?: string;
condition?: string;
limit?: number;
}
export interface WorkflowResult {
workflowId: string;
status: 'success' | 'error' | 'partial';
steps: WorkflowStepResult[];
duration: number;
}
export interface WorkflowStepResult {
step: number;
action: string;
status: 'success' | 'skipped' | 'error';
output?: unknown;
error?: string;
duration: number;
}
// ── Stream ──────────────────────────────────────────────────────────────────
export interface Stream {
id: string;
type: 'tweet' | 'follower' | 'mention';
username: string;
interval: number;
status: 'active' | 'stopped';
pollCount: number;
}
// ── Reputation ──────────────────────────────────────────────────────────────
export interface ReputationMonitor {
id: string;
target: string;
type: 'mentions' | 'keyword' | 'replies';
interval: number;
status: 'active' | 'stopped';
}
export interface ReputationReport {
username: string;
period: string;
sentimentDistribution: {
positive: number;
neutral: number;
negative: number;
};
topPositive: Tweet[];
topNegative: Tweet[];
timeline: Array<{ date: string; averageSentiment: number; count: number }>;
keywords: Array<{ word: string; count: number }>;
alerts: string[];
}
// ── Export ───────────────────────────────────────────────────────────────────
export interface ExportResult {
username: string;
formats: string[];
files: string[];
stats: {
profile: boolean;
tweets: number;
followers: number;
following: number;
bookmarks: number;
};
}
// ── Plugin ──────────────────────────────────────────────────────────────────
export interface Plugin {
name: string;
version: string;
description: string;
tools?: unknown[];
scrapers?: Record<string, Function>;
routes?: unknown[];
actions?: Record<string, Function>;
}
// ── Core Functions ──────────────────────────────────────────────────────────
/** Launch a Puppeteer browser with stealth mode */
export function createBrowser(options?: BrowserOptions): Promise<Browser>;
/** Create a new stealth page in the browser */
export function createPage(browser: Browser): Promise<Page>;
/** Scrape a user's profile data */
export function scrapeProfile(page: Page, username: string): Promise<Profile>;
/** Scrape a user's followers */
export function scrapeFollowers(page: Page, username: string, options?: ScrapeOptions): Promise<User[]>;
/** Scrape a user's following list */
export function scrapeFollowing(page: Page, username: string, options?: ScrapeOptions): Promise<User[]>;
/** Scrape a user's tweets */
export function scrapeTweets(page: Page, username: string, options?: ScrapeOptions): Promise<Tweet[]>;
/** Search tweets by query */
export function searchTweets(page: Page, query: string, options?: ScrapeOptions): Promise<Tweet[]>;
/** Download video from a tweet */
export function downloadVideo(page: Page, tweetUrl: string): Promise<VideoResult>;
/** Export bookmarks */
export function exportBookmarks(page: Page, options?: ScrapeOptions): Promise<Bookmark[]>;
/** Unroll a thread into a single document */
export function unrollThread(page: Page, tweetUrl: string): Promise<Thread>;
// ── Scrapers Module ─────────────────────────────────────────────────────────
export declare const scrapers: {
createBrowser: typeof createBrowser;
createPage: typeof createPage;
scrapeProfile: typeof scrapeProfile;
scrapeFollowers: typeof scrapeFollowers;
scrapeFollowing: typeof scrapeFollowing;
scrapeTweets: typeof scrapeTweets;
searchTweets: typeof searchTweets;
downloadVideo: typeof downloadVideo;
exportBookmarks: typeof exportBookmarks;
unrollThread: typeof unrollThread;
};
// ── Managers ────────────────────────────────────────────────────────────────
export declare const articlePublisher: unknown;
export declare const bookmarkManager: unknown;
export declare const businessTools: unknown;
export declare const creatorStudio: unknown;
export declare const discoveryExplore: unknown;
export declare const dmManager: unknown;
export declare const engagementManager: unknown;
export declare const grokIntegration: unknown;
export declare const notificationManager: unknown;
export declare const pollCreator: unknown;
export declare const postThread: unknown;
export declare const premiumManager: unknown;
export declare const profileManager: unknown;
export declare const schedulePosts: unknown;
export declare const settingsManager: unknown;
export declare const spacesManager: unknown;
export declare const tweetComposer: unknown;
// ── Plugin System ───────────────────────────────────────────────────────────
export declare const plugins: unknown;
export function initializePlugins(): Promise<void>;
export function installPlugin(name: string): Promise<Plugin>;
export function removePlugin(name: string): Promise<void>;
export function listPlugins(): Plugin[];
export function getPluginTools(): unknown[];
export function getPluginScrapers(): Record<string, Function>;
export function getPluginRoutes(): unknown[];
export function getPluginActions(): Record<string, Function>;
// ── Browser Scripts Catalog ─────────────────────────────────────────────────
export declare const browserScripts: Record<string, {
file: string;
description: string;
}>;
// ═══════════════════════════════════════════════════════════════════════════════
// HTTP Client (Track 01 — Programmatic Scraper)
// No Puppeteer required. Uses Twitter's internal GraphQL API via HTTP.
// ═══════════════════════════════════════════════════════════════════════════════
// ── Search Mode ─────────────────────────────────────────────────────────────
export declare const SearchMode: {
readonly Top: 'Top';
readonly Latest: 'Latest';
readonly Photos: 'Photos';
readonly Videos: 'Videos';
};
export type SearchModeType = typeof SearchMode[keyof typeof SearchMode];
// ── Scraper Options ─────────────────────────────────────────────────────────
export interface ScraperOptions {
/** Cookies string or array of {name, value} pairs */
cookies?: string | CookieEntry[];
/** Proxy URL (http, https, or socks5) */
proxy?: string;
/** Custom fetch implementation */
fetch?: typeof globalThis.fetch;
/** Request transform function applied before each request */
transform?: (request: RequestInit) => RequestInit | void;
}
export interface CookieEntry {
name: string;
value: string;
domain?: string;
path?: string;
}
export interface LoginCredentials {
username: string;
password: string;
email?: string;
}
export interface SendTweetOptions {
/** Media entity IDs to attach */
mediaIds?: string[];
/** Tweet ID to reply to */
replyTo?: string;
}
// ── Trend ───────────────────────────────────────────────────────────────────
export interface Trend {
name: string;
tweetCount: string;
url: string;
context: string;
}
// ── Poll ────────────────────────────────────────────────────────────────────
export interface PollOption {
label: string;
votes: number;
}
export interface Poll {
id: string;
options: PollOption[];
endDatetime: string | null;
votingStatus: 'open' | 'closed';
totalVotes: number;
}
// ── Client Tweet Model ──────────────────────────────────────────────────────
export interface ClientMediaItem {
id: string;
type: string;
url: string;
preview: string;
width: number;
height: number;
duration: number | null;
altText: string | null;
}
/**
* Tweet data model returned by the HTTP client Scraper.
* Created via `Tweet.fromGraphQL(raw)`.
*/
export declare class ClientTweet {
id: string;
text: string;
fullText: string;
username: string;
userId: string;
timeParsed: Date | null;
timestamp: number | null;
hashtags: string[];
mentions: string[];
urls: string[];
photos: Array<{ id: string; url: string; alt: string | null }>;
videos: Array<{ id: string; url: string; preview: string; duration: number | null }>;
thread: ClientTweet[];
inReplyToStatusId: string | null;
inReplyToStatus: ClientTweet | null;
quotedStatusId: string | null;
quotedStatus: ClientTweet | null;
isRetweet: boolean;
isReply: boolean;
isQuote: boolean;
retweetedStatus: ClientTweet | null;
likes: number;
retweets: number;
replies: number;
views: number;
bookmarkCount: number;
place: Record<string, unknown> | null;
sensitiveContent: boolean;
conversationId: string;
poll: Poll | null;
/**
* Parse a tweet from a raw Twitter GraphQL "tweet_results.result" object.
*/
static fromGraphQL(raw: Record<string, unknown>): ClientTweet | null;
}
// ── Client Profile Model ───────────────────────────────────────────────────
export interface Birthdate {
day: number | null;
month: number | null;
year: number | null;
visibility: string;
}
/**
* User profile returned by the HTTP client Scraper.
* Created via `Profile.fromGraphQL(raw)`.
*/
export declare class ClientProfile {
id: string;
username: string;
name: string;
bio: string;
location: string;
website: string;
joined: Date | null;
followersCount: number;
followingCount: number;
tweetCount: number;
likesCount: number;
listedCount: number;
mediaCount: number;
avatar: string;
banner: string;
verified: boolean;
protected: boolean;
birthdate: Birthdate | null;
pinnedTweetIds: string[];
isBlueVerified: boolean;
isGovernment: boolean;
isBusiness: boolean;
affiliatesCount: number;
canDm: boolean;
platform: string;
/** Full URL to profile on X */
readonly profileUrl: string;
/**
* Parse a profile from a raw Twitter GraphQL "user_results.result" object.
*/
static fromGraphQL(raw: Record<string, unknown>): ClientProfile | null;
/** JSON-serializable representation */
toJSON(): Record<string, unknown>;
}
// ── Client Message Model ───────────────────────────────────────────────────
/**
* Direct message returned by the HTTP client Scraper.
*/
export declare class ClientMessage {
id: string;
text: string;
senderId: string;
recipientId: string;
createdAt: Date | null;
mediaUrls: string[];
conversationId: string;
/**
* Parse a DM from a raw Twitter inbox API entry.
*/
static fromDmEntry(raw: Record<string, unknown>): ClientMessage | null;
/** JSON-serializable representation */
toJSON(): Record<string, unknown>;
}
/**
* DM conversation object.
*/
export declare class ClientConversation {
id: string;
type: 'ONE_TO_ONE' | 'GROUP_DM';
participantIds: string[];
lastMessage: ClientMessage | null;
updatedAt: Date | null;
}
// ── Error Classes ───────────────────────────────────────────────────────────
/**
* Base error for all XActions client errors.
*/
export declare class ScraperError extends Error {
code: string;
endpoint: string | null;
httpStatus: number | null;
rateLimitReset: number | null;
timestamp: Date;
constructor(message: string, code?: string, details?: Record<string, unknown>);
toString(): string;
toJSON(): Record<string, unknown>;
}
/**
* Thrown when authentication fails or is required.
*/
export declare class AuthenticationError extends ScraperError {
constructor(message: string, code?: string, details?: Record<string, unknown>);
}
/**
* Thrown when Twitter rate limits are exceeded.
*/
export declare class RateLimitError extends ScraperError {
retryAfter: number | null;
limit: number | null;
remaining: number;
resetAt: Date | null;
readonly retryAfterMs: number;
constructor(message?: string, details?: Record<string, unknown>);
}
/**
* Thrown when a requested resource does not exist.
*/
export declare class NotFoundError extends ScraperError {
constructor(message: string, code?: string, details?: Record<string, unknown>);
}
/**
* Wraps raw Twitter API errors with structured metadata.
*/
export declare class TwitterApiError extends ScraperError {
twitterErrorCode: number | null;
twitterMessage: string | null;
constructor(message: string, details?: Record<string, unknown>);
static fromTwitterError(error: Record<string, unknown>, details?: Record<string, unknown>): ScraperError;
static fromResponse(body: Record<string, unknown>, details?: Record<string, unknown>): ScraperError;
}
// ── Scraper Class ───────────────────────────────────────────────────────────
/**
* The main entry point for programmatic Twitter/X access via HTTP.
* No Puppeteer or browser required.
*
* @example
* ```js
* import { Scraper, SearchMode } from 'xactions/client';
*
* const scraper = new Scraper();
* await scraper.loadCookies('./cookies.json');
* const profile = await scraper.getProfile('elonmusk');
* for await (const tweet of scraper.getTweets('elonmusk', 20)) {
* console.log(tweet.text);
* }
* ```
*/
export declare class Scraper {
constructor(options?: ScraperOptions);
// ── Authentication ──────────────────────────────────────────────────
/** Log in with credentials (placeholder — use cookie-based auth until Track 02) */
login(credentials: LoginCredentials): Promise<void>;
/** Log out and clear all auth state */
logout(): Promise<void>;
/** Check if the scraper is authenticated */
isLoggedIn(): Promise<boolean>;
/** Get current cookies */
getCookies(): Promise<CookieEntry[]>;
/** Set cookies for authentication */
setCookies(cookies: CookieEntry[] | string): Promise<void>;
/** Save current cookies to a JSON file */
saveCookies(filePath: string): Promise<void>;
/** Load cookies from a JSON file */
loadCookies(filePath: string): Promise<void>;
// ── Users ───────────────────────────────────────────────────────────
/** Get a user's profile by screen name */
getProfile(username: string): Promise<ClientProfile>;
/** Get the authenticated user's profile */
me(): Promise<ClientProfile>;
/** Get a user's followers (requires userId, not username) */
getFollowers(userId: string, count?: number): AsyncGenerator<ClientProfile, void, undefined>;
/** Get accounts a user follows */
getFollowing(userId: string, count?: number): AsyncGenerator<ClientProfile, void, undefined>;
/** Follow a user by username */
followUser(username: string): Promise<void>;
/** Unfollow a user by username */
unfollowUser(username: string): Promise<void>;
// ── Tweets ──────────────────────────────────────────────────────────
/** Get a single tweet by ID */
getTweet(id: string): Promise<ClientTweet>;
/** Get tweets from a user's timeline */
getTweets(username: string, count?: number): AsyncGenerator<ClientTweet, void, undefined>;
/** Get tweets and replies from a user's timeline */
getTweetsAndReplies(username: string, count?: number): AsyncGenerator<ClientTweet, void, undefined>;
/** Get a user's liked tweets */
getLikedTweets(username: string, count?: number): AsyncGenerator<ClientTweet, void, undefined>;
/** Get the latest tweet from a user */
getLatestTweet(username: string): Promise<ClientTweet | null>;
/** Post a new tweet */
sendTweet(text: string, options?: SendTweetOptions): Promise<ClientTweet>;
/** Post a quote tweet */
sendQuoteTweet(text: string, quotedTweetId: string, mediaIds?: string[]): Promise<ClientTweet>;
/** Delete a tweet */
deleteTweet(id: string): Promise<void>;
/** Like a tweet */
likeTweet(id: string): Promise<void>;
/** Unlike a tweet */
unlikeTweet(id: string): Promise<void>;
/** Retweet a tweet */
retweet(id: string): Promise<void>;
/** Remove a retweet */
unretweet(id: string): Promise<void>;
// ── Search ──────────────────────────────────────────────────────────
/** Search tweets with query and optional mode */
searchTweets(query: string, count?: number, mode?: SearchModeType): AsyncGenerator<ClientTweet, void, undefined>;
/** Search user profiles */
searchProfiles(query: string, count?: number): AsyncGenerator<ClientProfile, void, undefined>;
// ── Trends ──────────────────────────────────────────────────────────
/** Get current trending topics */
getTrends(): Promise<Trend[]>;
// ── Lists ───────────────────────────────────────────────────────────
/** Get tweets from a Twitter List */
getListTweets(listId: string, count?: number): AsyncGenerator<ClientTweet, void, undefined>;
// ── Direct Messages ─────────────────────────────────────────────────
/** Send a direct message to a user by their numeric ID */
sendDm(userId: string, text: string): Promise<void>;
}
// ── GraphQL Constants ───────────────────────────────────────────────────────
export declare const BEARER_TOKEN: string;
export declare const DEFAULT_FEATURES: Record<string, boolean>;
export declare const GRAPHQL_ENDPOINTS: Record<string, { queryId: string; operationName: string }>;
export declare function buildGraphQLUrl(
endpoint: { queryId: string; operationName: string },
variables: Record<string, unknown>,
features?: Record<string, boolean>,
fieldToggles?: Record<string, boolean>,
): string;