scrapebadger 0.1.0

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.
@@ -0,0 +1,1105 @@
1
+ // src/internal/pagination.ts
2
+ function createPaginatedResponse(data, cursor) {
3
+ return {
4
+ data,
5
+ nextCursor: cursor,
6
+ hasMore: !!cursor
7
+ };
8
+ }
9
+ async function* paginate(fetchPage, options = {}) {
10
+ const { maxItems } = options;
11
+ let cursor;
12
+ let totalYielded = 0;
13
+ do {
14
+ const response = await fetchPage(cursor);
15
+ for (const item of response.data) {
16
+ yield item;
17
+ totalYielded++;
18
+ if (maxItems !== void 0 && totalYielded >= maxItems) {
19
+ return;
20
+ }
21
+ }
22
+ cursor = response.nextCursor;
23
+ } while (cursor);
24
+ }
25
+
26
+ // src/twitter/tweets.ts
27
+ var TweetsClient = class {
28
+ client;
29
+ constructor(client) {
30
+ this.client = client;
31
+ }
32
+ /**
33
+ * Get a single tweet by ID.
34
+ *
35
+ * @param tweetId - The tweet ID to fetch.
36
+ * @returns The tweet data.
37
+ * @throws NotFoundError - If the tweet doesn't exist.
38
+ * @throws AuthenticationError - If the API key is invalid.
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const tweet = await client.twitter.tweets.getById("1234567890");
43
+ * console.log(`@${tweet.username}: ${tweet.text}`);
44
+ * ```
45
+ */
46
+ async getById(tweetId) {
47
+ return this.client.request(`/v1/twitter/tweets/tweet/${tweetId}`);
48
+ }
49
+ /**
50
+ * Get multiple tweets by their IDs.
51
+ *
52
+ * @param tweetIds - List of tweet IDs to fetch.
53
+ * @returns Paginated response containing the tweets.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const tweets = await client.twitter.tweets.getByIds([
58
+ * "1234567890",
59
+ * "0987654321"
60
+ * ]);
61
+ * for (const tweet of tweets.data) {
62
+ * console.log(tweet.text);
63
+ * }
64
+ * ```
65
+ */
66
+ async getByIds(tweetIds) {
67
+ const tweetsParam = tweetIds.join(",");
68
+ const response = await this.client.request(
69
+ "/v1/twitter/tweets/",
70
+ { params: { tweets: tweetsParam } }
71
+ );
72
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
73
+ }
74
+ /**
75
+ * Get replies to a tweet.
76
+ *
77
+ * @param tweetId - The tweet ID to get replies for.
78
+ * @param options - Pagination options.
79
+ * @returns Paginated response containing reply tweets.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const replies = await client.twitter.tweets.getReplies("1234567890");
84
+ * for (const reply of replies.data) {
85
+ * console.log(`@${reply.username}: ${reply.text}`);
86
+ * }
87
+ *
88
+ * // Get next page
89
+ * if (replies.hasMore) {
90
+ * const more = await client.twitter.tweets.getReplies("1234567890", {
91
+ * cursor: replies.nextCursor
92
+ * });
93
+ * }
94
+ * ```
95
+ */
96
+ async getReplies(tweetId, options = {}) {
97
+ const response = await this.client.request(
98
+ `/v1/twitter/tweets/tweet/${tweetId}/replies`,
99
+ { params: { cursor: options.cursor } }
100
+ );
101
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
102
+ }
103
+ /**
104
+ * Get users who retweeted a tweet.
105
+ *
106
+ * @param tweetId - The tweet ID to get retweeters for.
107
+ * @param options - Pagination options.
108
+ * @returns Paginated response containing users who retweeted.
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const retweeters = await client.twitter.tweets.getRetweeters("1234567890");
113
+ * for (const user of retweeters.data) {
114
+ * console.log(`@${user.username} retweeted`);
115
+ * }
116
+ * ```
117
+ */
118
+ async getRetweeters(tweetId, options = {}) {
119
+ const response = await this.client.request(
120
+ `/v1/twitter/tweets/tweet/${tweetId}/retweeters`,
121
+ { params: { cursor: options.cursor } }
122
+ );
123
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
124
+ }
125
+ /**
126
+ * Get users who liked/favorited a tweet.
127
+ *
128
+ * @param tweetId - The tweet ID to get favoriters for.
129
+ * @param options - Pagination options with optional count.
130
+ * @returns Paginated response containing users who liked.
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * const likers = await client.twitter.tweets.getFavoriters("1234567890");
135
+ * console.log(`${likers.data.length} users liked this tweet`);
136
+ * ```
137
+ */
138
+ async getFavoriters(tweetId, options = {}) {
139
+ const response = await this.client.request(
140
+ `/v1/twitter/tweets/tweet/${tweetId}/favoriters`,
141
+ { params: { count: options.count ?? 40, cursor: options.cursor } }
142
+ );
143
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
144
+ }
145
+ /**
146
+ * Get tweets similar to a given tweet.
147
+ *
148
+ * @param tweetId - The tweet ID to find similar tweets for.
149
+ * @returns Paginated response containing similar tweets.
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const similar = await client.twitter.tweets.getSimilar("1234567890");
154
+ * for (const tweet of similar.data) {
155
+ * console.log(`Similar: ${tweet.text.slice(0, 100)}...`);
156
+ * }
157
+ * ```
158
+ */
159
+ async getSimilar(tweetId) {
160
+ const response = await this.client.request(
161
+ `/v1/twitter/tweets/tweet/${tweetId}/similar`
162
+ );
163
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
164
+ }
165
+ /**
166
+ * Search for tweets.
167
+ *
168
+ * @param query - Search query string. Supports Twitter advanced search operators.
169
+ * @param options - Search options including query type and pagination.
170
+ * @returns Paginated response containing matching tweets.
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * // Basic search
175
+ * const results = await client.twitter.tweets.search("python programming");
176
+ *
177
+ * // Latest tweets only
178
+ * const latest = await client.twitter.tweets.search("python", {
179
+ * queryType: "Latest"
180
+ * });
181
+ *
182
+ * // Advanced search operators
183
+ * const fromUser = await client.twitter.tweets.search("from:elonmusk lang:en");
184
+ * ```
185
+ */
186
+ async search(query, options = {}) {
187
+ const response = await this.client.request(
188
+ "/v1/twitter/tweets/advanced_search",
189
+ {
190
+ params: {
191
+ query,
192
+ query_type: options.queryType ?? "Top",
193
+ cursor: options.cursor
194
+ }
195
+ }
196
+ );
197
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
198
+ }
199
+ /**
200
+ * Iterate through all search results with automatic pagination.
201
+ *
202
+ * This is a convenience method that automatically handles pagination,
203
+ * yielding tweets one at a time.
204
+ *
205
+ * @param query - Search query string.
206
+ * @param options - Search and iteration options.
207
+ * @yields Tweet objects matching the search query.
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * // Get up to 1000 tweets
212
+ * for await (const tweet of client.twitter.tweets.searchAll("python", {
213
+ * maxItems: 1000
214
+ * })) {
215
+ * console.log(tweet.text);
216
+ * }
217
+ *
218
+ * // Collect into an array
219
+ * import { collectAll } from "scrapebadger";
220
+ * const tweets = await collectAll(
221
+ * client.twitter.tweets.searchAll("python", { maxItems: 100 })
222
+ * );
223
+ * ```
224
+ */
225
+ async *searchAll(query, options = {}) {
226
+ const fetchPage = async (cursor) => {
227
+ return this.search(query, { ...options, cursor });
228
+ };
229
+ yield* paginate(fetchPage, options);
230
+ }
231
+ /**
232
+ * Get tweets from a user's timeline.
233
+ *
234
+ * @param username - Twitter username (without @).
235
+ * @param options - Pagination options.
236
+ * @returns Paginated response containing the user's tweets.
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * const tweets = await client.twitter.tweets.getUserTweets("elonmusk");
241
+ * for (const tweet of tweets.data) {
242
+ * console.log(`${tweet.created_at}: ${tweet.text.slice(0, 100)}...`);
243
+ * }
244
+ * ```
245
+ */
246
+ async getUserTweets(username, options = {}) {
247
+ const response = await this.client.request(
248
+ `/v1/twitter/users/${username}/latest_tweets`,
249
+ { params: { cursor: options.cursor } }
250
+ );
251
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
252
+ }
253
+ /**
254
+ * Iterate through all tweets from a user with automatic pagination.
255
+ *
256
+ * @param username - Twitter username (without @).
257
+ * @param options - Iteration options.
258
+ * @yields Tweet objects from the user's timeline.
259
+ *
260
+ * @example
261
+ * ```typescript
262
+ * for await (const tweet of client.twitter.tweets.getUserTweetsAll("elonmusk", {
263
+ * maxItems: 500
264
+ * })) {
265
+ * console.log(tweet.text);
266
+ * }
267
+ * ```
268
+ */
269
+ async *getUserTweetsAll(username, options = {}) {
270
+ const fetchPage = async (cursor) => {
271
+ return this.getUserTweets(username, { ...options, cursor });
272
+ };
273
+ yield* paginate(fetchPage, options);
274
+ }
275
+ };
276
+
277
+ // src/twitter/users.ts
278
+ var UsersClient = class {
279
+ client;
280
+ constructor(client) {
281
+ this.client = client;
282
+ }
283
+ /**
284
+ * Get a user by their numeric ID.
285
+ *
286
+ * @param userId - The user's numeric ID.
287
+ * @returns The user profile.
288
+ * @throws NotFoundError - If the user doesn't exist.
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * const user = await client.twitter.users.getById("44196397");
293
+ * console.log(`@${user.username}`);
294
+ * ```
295
+ */
296
+ async getById(userId) {
297
+ return this.client.request(`/v1/twitter/users/${userId}/by_id`);
298
+ }
299
+ /**
300
+ * Get a user by their username.
301
+ *
302
+ * @param username - The user's username (without @).
303
+ * @returns The user profile.
304
+ * @throws NotFoundError - If the user doesn't exist.
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * const user = await client.twitter.users.getByUsername("elonmusk");
309
+ * console.log(`${user.name} has ${user.followers_count.toLocaleString()} followers`);
310
+ * ```
311
+ */
312
+ async getByUsername(username) {
313
+ return this.client.request(`/v1/twitter/users/${username}/by_username`);
314
+ }
315
+ /**
316
+ * Get extended "About" information for a user.
317
+ *
318
+ * Returns additional metadata including account location,
319
+ * username change history, and verification details.
320
+ *
321
+ * @param username - The user's username (without @).
322
+ * @returns Extended user information.
323
+ *
324
+ * @example
325
+ * ```typescript
326
+ * const about = await client.twitter.users.getAbout("elonmusk");
327
+ * console.log(`Account based in: ${about.account_based_in}`);
328
+ * console.log(`Username changes: ${about.username_changes}`);
329
+ * ```
330
+ */
331
+ async getAbout(username) {
332
+ return this.client.request(`/v1/twitter/users/${username}/about`);
333
+ }
334
+ /**
335
+ * Get a user's followers.
336
+ *
337
+ * @param username - The user's username (without @).
338
+ * @param options - Pagination options.
339
+ * @returns Paginated response containing follower users.
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * const followers = await client.twitter.users.getFollowers("elonmusk");
344
+ * for (const user of followers.data) {
345
+ * console.log(`@${user.username}`);
346
+ * }
347
+ *
348
+ * // Get next page
349
+ * if (followers.hasMore) {
350
+ * const more = await client.twitter.users.getFollowers("elonmusk", {
351
+ * cursor: followers.nextCursor
352
+ * });
353
+ * }
354
+ * ```
355
+ */
356
+ async getFollowers(username, options = {}) {
357
+ const response = await this.client.request(
358
+ `/v1/twitter/users/${username}/followers`,
359
+ { params: { cursor: options.cursor } }
360
+ );
361
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
362
+ }
363
+ /**
364
+ * Iterate through all followers with automatic pagination.
365
+ *
366
+ * @param username - The user's username (without @).
367
+ * @param options - Iteration options.
368
+ * @yields User objects for each follower.
369
+ *
370
+ * @example
371
+ * ```typescript
372
+ * for await (const follower of client.twitter.users.getFollowersAll("elonmusk", {
373
+ * maxItems: 1000
374
+ * })) {
375
+ * console.log(follower.username);
376
+ * }
377
+ * ```
378
+ */
379
+ async *getFollowersAll(username, options = {}) {
380
+ const fetchPage = async (cursor) => {
381
+ return this.getFollowers(username, { ...options, cursor });
382
+ };
383
+ yield* paginate(fetchPage, options);
384
+ }
385
+ /**
386
+ * Get users that a user is following.
387
+ *
388
+ * @param username - The user's username (without @).
389
+ * @param options - Pagination options.
390
+ * @returns Paginated response containing followed users.
391
+ *
392
+ * @example
393
+ * ```typescript
394
+ * const following = await client.twitter.users.getFollowing("elonmusk");
395
+ * for (const user of following.data) {
396
+ * console.log(`Follows @${user.username}`);
397
+ * }
398
+ * ```
399
+ */
400
+ async getFollowing(username, options = {}) {
401
+ const response = await this.client.request(
402
+ `/v1/twitter/users/${username}/followings`,
403
+ { params: { cursor: options.cursor } }
404
+ );
405
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
406
+ }
407
+ /**
408
+ * Iterate through all following with automatic pagination.
409
+ *
410
+ * @param username - The user's username (without @).
411
+ * @param options - Iteration options.
412
+ * @yields User objects for each followed account.
413
+ */
414
+ async *getFollowingAll(username, options = {}) {
415
+ const fetchPage = async (cursor) => {
416
+ return this.getFollowing(username, { ...options, cursor });
417
+ };
418
+ yield* paginate(fetchPage, options);
419
+ }
420
+ /**
421
+ * Get a user's most recent followers.
422
+ *
423
+ * @param username - The user's username (without @).
424
+ * @param options - Pagination options with optional count.
425
+ * @returns Paginated response containing recent followers.
426
+ */
427
+ async getLatestFollowers(username, options = {}) {
428
+ const response = await this.client.request(
429
+ `/v1/twitter/users/${username}/latest_followers`,
430
+ { params: { count: options.count ?? 200, cursor: options.cursor } }
431
+ );
432
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
433
+ }
434
+ /**
435
+ * Get accounts a user most recently followed.
436
+ *
437
+ * @param username - The user's username (without @).
438
+ * @param options - Pagination options with optional count.
439
+ * @returns Paginated response containing recently followed users.
440
+ */
441
+ async getLatestFollowing(username, options = {}) {
442
+ const response = await this.client.request(
443
+ `/v1/twitter/users/${username}/latest_following`,
444
+ { params: { count: options.count ?? 200, cursor: options.cursor } }
445
+ );
446
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
447
+ }
448
+ /**
449
+ * Get follower IDs for a user.
450
+ *
451
+ * More efficient than getFollowers when you only need IDs.
452
+ *
453
+ * @param username - The user's username (without @).
454
+ * @param options - Pagination options with optional count.
455
+ * @returns UserIds containing list of follower IDs.
456
+ *
457
+ * @example
458
+ * ```typescript
459
+ * const ids = await client.twitter.users.getFollowerIds("elonmusk");
460
+ * console.log(`Found ${ids.ids.length.toLocaleString()} follower IDs`);
461
+ * ```
462
+ */
463
+ async getFollowerIds(username, options = {}) {
464
+ const response = await this.client.request(
465
+ `/v1/twitter/users/${username}/follower_ids`,
466
+ { params: { count: options.count ?? 5e3, cursor: options.cursor } }
467
+ );
468
+ return {
469
+ ids: response.data?.ids ?? [],
470
+ next_cursor: response.data?.next_cursor
471
+ };
472
+ }
473
+ /**
474
+ * Get following IDs for a user.
475
+ *
476
+ * More efficient than getFollowing when you only need IDs.
477
+ *
478
+ * @param username - The user's username (without @).
479
+ * @param options - Pagination options with optional count.
480
+ * @returns UserIds containing list of following IDs.
481
+ */
482
+ async getFollowingIds(username, options = {}) {
483
+ const response = await this.client.request(
484
+ `/v1/twitter/users/${username}/following_ids`,
485
+ { params: { count: options.count ?? 5e3, cursor: options.cursor } }
486
+ );
487
+ return {
488
+ ids: response.data?.ids ?? [],
489
+ next_cursor: response.data?.next_cursor
490
+ };
491
+ }
492
+ /**
493
+ * Get verified followers for a user.
494
+ *
495
+ * @param userId - The user's numeric ID.
496
+ * @param options - Pagination options with optional count.
497
+ * @returns Paginated response containing verified followers.
498
+ */
499
+ async getVerifiedFollowers(userId, options = {}) {
500
+ const response = await this.client.request(
501
+ `/v1/twitter/users/${userId}/verified_followers`,
502
+ { params: { count: options.count ?? 20, cursor: options.cursor } }
503
+ );
504
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
505
+ }
506
+ /**
507
+ * Get followers that the authenticated user also follows.
508
+ *
509
+ * @param userId - The user's numeric ID.
510
+ * @param options - Pagination options with optional count.
511
+ * @returns Paginated response containing mutual connections.
512
+ */
513
+ async getFollowersYouKnow(userId, options = {}) {
514
+ const response = await this.client.request(
515
+ `/v1/twitter/users/${userId}/followers_you_know`,
516
+ { params: { count: options.count ?? 20, cursor: options.cursor } }
517
+ );
518
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
519
+ }
520
+ /**
521
+ * Get premium accounts that a user subscribes to.
522
+ *
523
+ * @param userId - The user's numeric ID.
524
+ * @param options - Pagination options with optional count.
525
+ * @returns Paginated response containing subscribed accounts.
526
+ */
527
+ async getSubscriptions(userId, options = {}) {
528
+ const response = await this.client.request(
529
+ `/v1/twitter/users/${userId}/subscriptions`,
530
+ { params: { count: options.count ?? 20, cursor: options.cursor } }
531
+ );
532
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
533
+ }
534
+ /**
535
+ * Get a user's highlighted tweets.
536
+ *
537
+ * @param userId - The user's numeric ID.
538
+ * @param options - Pagination options with optional count.
539
+ * @returns Paginated response containing highlighted tweets.
540
+ */
541
+ async getHighlights(userId, options = {}) {
542
+ const response = await this.client.request(
543
+ `/v1/twitter/users/${userId}/highlights`,
544
+ { params: { count: options.count ?? 20, cursor: options.cursor } }
545
+ );
546
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
547
+ }
548
+ /**
549
+ * Search for users.
550
+ *
551
+ * @param query - Search query string.
552
+ * @param options - Pagination options.
553
+ * @returns Paginated response containing matching users.
554
+ *
555
+ * @example
556
+ * ```typescript
557
+ * const results = await client.twitter.users.search("python developer");
558
+ * for (const user of results.data) {
559
+ * console.log(`@${user.username}: ${user.description}`);
560
+ * }
561
+ * ```
562
+ */
563
+ async search(query, options = {}) {
564
+ const response = await this.client.request(
565
+ "/v1/twitter/users/search_users",
566
+ { params: { query, cursor: options.cursor } }
567
+ );
568
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
569
+ }
570
+ /**
571
+ * Iterate through all search results with automatic pagination.
572
+ *
573
+ * @param query - Search query string.
574
+ * @param options - Iteration options.
575
+ * @yields User objects matching the search query.
576
+ */
577
+ async *searchAll(query, options = {}) {
578
+ const fetchPage = async (cursor) => {
579
+ return this.search(query, { ...options, cursor });
580
+ };
581
+ yield* paginate(fetchPage, options);
582
+ }
583
+ };
584
+
585
+ // src/twitter/lists.ts
586
+ var ListsClient = class {
587
+ client;
588
+ constructor(client) {
589
+ this.client = client;
590
+ }
591
+ /**
592
+ * Get details for a specific list.
593
+ *
594
+ * @param listId - The list ID.
595
+ * @returns The list details.
596
+ * @throws NotFoundError - If the list doesn't exist.
597
+ *
598
+ * @example
599
+ * ```typescript
600
+ * const list = await client.twitter.lists.getDetail("123456");
601
+ * console.log(`${list.name} by @${list.username}`);
602
+ * console.log(`${list.member_count} members, ${list.subscriber_count} subscribers`);
603
+ * ```
604
+ */
605
+ async getDetail(listId) {
606
+ return this.client.request(`/v1/twitter/lists/${listId}/detail`);
607
+ }
608
+ /**
609
+ * Get tweets from a list's timeline.
610
+ *
611
+ * @param listId - The list ID.
612
+ * @param options - Pagination options.
613
+ * @returns Paginated response containing tweets from list members.
614
+ *
615
+ * @example
616
+ * ```typescript
617
+ * const tweets = await client.twitter.lists.getTweets("123456");
618
+ * for (const tweet of tweets.data) {
619
+ * console.log(`@${tweet.username}: ${tweet.text.slice(0, 100)}...`);
620
+ * }
621
+ * ```
622
+ */
623
+ async getTweets(listId, options = {}) {
624
+ const response = await this.client.request(
625
+ `/v1/twitter/lists/${listId}/tweets`,
626
+ { params: { cursor: options.cursor } }
627
+ );
628
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
629
+ }
630
+ /**
631
+ * Iterate through all list tweets with automatic pagination.
632
+ *
633
+ * @param listId - The list ID.
634
+ * @param options - Iteration options.
635
+ * @yields Tweet objects from the list timeline.
636
+ */
637
+ async *getTweetsAll(listId, options = {}) {
638
+ const fetchPage = async (cursor) => {
639
+ return this.getTweets(listId, { ...options, cursor });
640
+ };
641
+ yield* paginate(fetchPage, options);
642
+ }
643
+ /**
644
+ * Get members of a list.
645
+ *
646
+ * @param listId - The list ID.
647
+ * @param options - Pagination options.
648
+ * @returns Paginated response containing list members.
649
+ *
650
+ * @example
651
+ * ```typescript
652
+ * const members = await client.twitter.lists.getMembers("123456");
653
+ * for (const user of members.data) {
654
+ * console.log(`@${user.username}`);
655
+ * }
656
+ * ```
657
+ */
658
+ async getMembers(listId, options = {}) {
659
+ const response = await this.client.request(
660
+ `/v1/twitter/lists/${listId}/members`,
661
+ { params: { cursor: options.cursor } }
662
+ );
663
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
664
+ }
665
+ /**
666
+ * Iterate through all list members with automatic pagination.
667
+ *
668
+ * @param listId - The list ID.
669
+ * @param options - Iteration options.
670
+ * @yields User objects for each list member.
671
+ */
672
+ async *getMembersAll(listId, options = {}) {
673
+ const fetchPage = async (cursor) => {
674
+ return this.getMembers(listId, { ...options, cursor });
675
+ };
676
+ yield* paginate(fetchPage, options);
677
+ }
678
+ /**
679
+ * Get subscribers of a list.
680
+ *
681
+ * @param listId - The list ID.
682
+ * @param options - Pagination options with optional count.
683
+ * @returns Paginated response containing list subscribers.
684
+ */
685
+ async getSubscribers(listId, options = {}) {
686
+ const response = await this.client.request(
687
+ `/v1/twitter/lists/${listId}/subscribers`,
688
+ { params: { count: options.count ?? 20, cursor: options.cursor } }
689
+ );
690
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
691
+ }
692
+ /**
693
+ * Search for lists.
694
+ *
695
+ * @param query - Search query string.
696
+ * @param options - Pagination options with optional count.
697
+ * @returns Paginated response containing matching lists.
698
+ *
699
+ * @example
700
+ * ```typescript
701
+ * const results = await client.twitter.lists.search("tech leaders");
702
+ * for (const list of results.data) {
703
+ * console.log(`${list.name}: ${list.member_count} members`);
704
+ * }
705
+ * ```
706
+ */
707
+ async search(query, options = {}) {
708
+ const response = await this.client.request(
709
+ "/v1/twitter/lists/search",
710
+ { params: { query, count: options.count ?? 20, cursor: options.cursor } }
711
+ );
712
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
713
+ }
714
+ /**
715
+ * Get lists owned by the authenticated user.
716
+ *
717
+ * @param options - Pagination options with optional count.
718
+ * @returns Paginated response containing the user's lists.
719
+ */
720
+ async getMyLists(options = {}) {
721
+ const response = await this.client.request(
722
+ "/v1/twitter/lists/my_lists",
723
+ { params: { count: options.count ?? 100, cursor: options.cursor } }
724
+ );
725
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
726
+ }
727
+ };
728
+
729
+ // src/twitter/communities.ts
730
+ var CommunitiesClient = class {
731
+ client;
732
+ constructor(client) {
733
+ this.client = client;
734
+ }
735
+ /**
736
+ * Get details for a specific community.
737
+ *
738
+ * @param communityId - The community ID.
739
+ * @returns The community details including rules and admin info.
740
+ * @throws NotFoundError - If the community doesn't exist.
741
+ *
742
+ * @example
743
+ * ```typescript
744
+ * const community = await client.twitter.communities.getDetail("123456");
745
+ * console.log(`${community.name}`);
746
+ * console.log(`Members: ${community.member_count?.toLocaleString()}`);
747
+ * console.log(`Join policy: ${community.join_policy}`);
748
+ *
749
+ * if (community.rules) {
750
+ * console.log("Rules:");
751
+ * for (const rule of community.rules) {
752
+ * console.log(` - ${rule.name}`);
753
+ * }
754
+ * }
755
+ * ```
756
+ */
757
+ async getDetail(communityId) {
758
+ return this.client.request(`/v1/twitter/communities/${communityId}`);
759
+ }
760
+ /**
761
+ * Get tweets from a community.
762
+ *
763
+ * @param communityId - The community ID.
764
+ * @param options - Options including tweet type, count, and pagination.
765
+ * @returns Paginated response containing community tweets.
766
+ *
767
+ * @example
768
+ * ```typescript
769
+ * // Get top tweets
770
+ * const tweets = await client.twitter.communities.getTweets("123456");
771
+ *
772
+ * // Get latest tweets
773
+ * const latest = await client.twitter.communities.getTweets("123456", {
774
+ * tweetType: "Latest"
775
+ * });
776
+ * ```
777
+ */
778
+ async getTweets(communityId, options = {}) {
779
+ const response = await this.client.request(
780
+ `/v1/twitter/communities/${communityId}/tweets`,
781
+ {
782
+ params: {
783
+ tweet_type: options.tweetType ?? "Top",
784
+ count: options.count ?? 40,
785
+ cursor: options.cursor
786
+ }
787
+ }
788
+ );
789
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
790
+ }
791
+ /**
792
+ * Iterate through all community tweets with automatic pagination.
793
+ *
794
+ * @param communityId - The community ID.
795
+ * @param options - Options including tweet type and iteration limits.
796
+ * @yields Tweet objects from the community.
797
+ */
798
+ async *getTweetsAll(communityId, options = {}) {
799
+ const fetchPage = async (cursor) => {
800
+ return this.getTweets(communityId, { ...options, cursor });
801
+ };
802
+ yield* paginate(fetchPage, options);
803
+ }
804
+ /**
805
+ * Get members of a community.
806
+ *
807
+ * @param communityId - The community ID.
808
+ * @param options - Pagination options with optional count.
809
+ * @returns Paginated response containing community members.
810
+ *
811
+ * @example
812
+ * ```typescript
813
+ * const members = await client.twitter.communities.getMembers("123456");
814
+ * for (const member of members.data) {
815
+ * console.log(`@${member.user.username} (${member.role})`);
816
+ * }
817
+ * ```
818
+ */
819
+ async getMembers(communityId, options = {}) {
820
+ const response = await this.client.request(`/v1/twitter/communities/${communityId}/members`, {
821
+ params: { count: options.count ?? 20, cursor: options.cursor }
822
+ });
823
+ const data = (response.data ?? []).map((item) => {
824
+ if ("user" in item && item.user) {
825
+ return item;
826
+ }
827
+ const userItem = item;
828
+ return {
829
+ user: item,
830
+ role: userItem.role,
831
+ joined_at: userItem.joined_at
832
+ };
833
+ });
834
+ return createPaginatedResponse(data, response.next_cursor);
835
+ }
836
+ /**
837
+ * Get moderators of a community.
838
+ *
839
+ * @param communityId - The community ID.
840
+ * @param options - Pagination options with optional count.
841
+ * @returns Paginated response containing community moderators.
842
+ */
843
+ async getModerators(communityId, options = {}) {
844
+ const response = await this.client.request(`/v1/twitter/communities/${communityId}/moderators`, {
845
+ params: { count: options.count ?? 20, cursor: options.cursor }
846
+ });
847
+ const data = (response.data ?? []).map((item) => {
848
+ if ("user" in item && item.user) {
849
+ return item;
850
+ }
851
+ const userItem = item;
852
+ return {
853
+ user: item,
854
+ role: "moderator",
855
+ joined_at: userItem.joined_at
856
+ };
857
+ });
858
+ return createPaginatedResponse(data, response.next_cursor);
859
+ }
860
+ /**
861
+ * Search for communities.
862
+ *
863
+ * @param query - Search query string.
864
+ * @param options - Pagination options.
865
+ * @returns Paginated response containing matching communities.
866
+ *
867
+ * @example
868
+ * ```typescript
869
+ * const results = await client.twitter.communities.search("python developers");
870
+ * for (const community of results.data) {
871
+ * console.log(`${community.name}: ${community.member_count} members`);
872
+ * }
873
+ * ```
874
+ */
875
+ async search(query, options = {}) {
876
+ const response = await this.client.request(
877
+ "/v1/twitter/communities/search",
878
+ { params: { query, cursor: options.cursor } }
879
+ );
880
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
881
+ }
882
+ /**
883
+ * Search for tweets within a community.
884
+ *
885
+ * @param communityId - The community ID.
886
+ * @param query - Search query string.
887
+ * @param options - Pagination options with optional count.
888
+ * @returns Paginated response containing matching tweets.
889
+ */
890
+ async searchTweets(communityId, query, options = {}) {
891
+ const response = await this.client.request(
892
+ `/v1/twitter/communities/${communityId}/search_tweets`,
893
+ { params: { query, count: options.count ?? 20, cursor: options.cursor } }
894
+ );
895
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
896
+ }
897
+ /**
898
+ * Get the community timeline (tweets from communities you're in).
899
+ *
900
+ * @param options - Pagination options with optional count.
901
+ * @returns Paginated response containing community timeline tweets.
902
+ */
903
+ async getTimeline(options = {}) {
904
+ const response = await this.client.request(
905
+ "/v1/twitter/communities/timeline",
906
+ { params: { count: options.count ?? 20, cursor: options.cursor } }
907
+ );
908
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
909
+ }
910
+ };
911
+
912
+ // src/twitter/trends.ts
913
+ var TrendsClient = class {
914
+ client;
915
+ constructor(client) {
916
+ this.client = client;
917
+ }
918
+ /**
919
+ * Get trending topics.
920
+ *
921
+ * @param options - Options for filtering trends.
922
+ * @returns Paginated response containing trending topics.
923
+ *
924
+ * @example
925
+ * ```typescript
926
+ * // Get general trending topics
927
+ * const trends = await client.twitter.trends.getTrends();
928
+ *
929
+ * // Get news trends
930
+ * const newsTrends = await client.twitter.trends.getTrends({
931
+ * category: "news"
932
+ * });
933
+ *
934
+ * for (const trend of trends.data) {
935
+ * const count = trend.tweet_count?.toLocaleString() || "N/A";
936
+ * console.log(`${trend.name}: ${count} tweets`);
937
+ * }
938
+ * ```
939
+ */
940
+ async getTrends(options = {}) {
941
+ const response = await this.client.request("/v1/twitter/trends/", {
942
+ params: {
943
+ category: options.category ?? "trending",
944
+ count: options.count ?? 20
945
+ }
946
+ });
947
+ return createPaginatedResponse(response.data ?? []);
948
+ }
949
+ /**
950
+ * Get trends for a specific location.
951
+ *
952
+ * @param woeid - Where On Earth ID for the location.
953
+ * Common WOEIDs:
954
+ * - 1: Worldwide
955
+ * - 23424977: United States
956
+ * - 23424975: United Kingdom
957
+ * - 23424856: Japan
958
+ * - 23424829: Germany
959
+ * @returns PlaceTrends containing location info and trends.
960
+ * @throws NotFoundError - If the WOEID is invalid.
961
+ *
962
+ * @example
963
+ * ```typescript
964
+ * // Get US trends
965
+ * const usTrends = await client.twitter.trends.getPlaceTrends(23424977);
966
+ * console.log(`Trends in ${usTrends.name}:`);
967
+ * for (const trend of usTrends.trends) {
968
+ * console.log(` - ${trend.name}`);
969
+ * }
970
+ *
971
+ * // Get worldwide trends
972
+ * const globalTrends = await client.twitter.trends.getPlaceTrends(1);
973
+ * ```
974
+ */
975
+ async getPlaceTrends(woeid) {
976
+ return this.client.request(`/v1/twitter/trends/place/${woeid}`);
977
+ }
978
+ /**
979
+ * Get all locations where trends are available.
980
+ *
981
+ * @returns Paginated response containing available trend locations.
982
+ *
983
+ * @example
984
+ * ```typescript
985
+ * const locations = await client.twitter.trends.getAvailableLocations();
986
+ *
987
+ * // Filter by country
988
+ * const usLocations = locations.data.filter(
989
+ * loc => loc.country_code === "US"
990
+ * );
991
+ * console.log(`Found ${usLocations.length} US locations`);
992
+ *
993
+ * // Get countries only
994
+ * const countries = locations.data.filter(
995
+ * loc => loc.place_type === "Country"
996
+ * );
997
+ * ```
998
+ */
999
+ async getAvailableLocations() {
1000
+ const response = await this.client.request(
1001
+ "/v1/twitter/trends/locations"
1002
+ );
1003
+ return createPaginatedResponse(response.data ?? []);
1004
+ }
1005
+ };
1006
+
1007
+ // src/twitter/geo.ts
1008
+ var GeoClient = class {
1009
+ client;
1010
+ constructor(client) {
1011
+ this.client = client;
1012
+ }
1013
+ /**
1014
+ * Get details for a specific place.
1015
+ *
1016
+ * @param placeId - The Twitter place ID.
1017
+ * @returns The place details.
1018
+ * @throws NotFoundError - If the place doesn't exist.
1019
+ *
1020
+ * @example
1021
+ * ```typescript
1022
+ * const place = await client.twitter.geo.getDetail("5a110d312052166f");
1023
+ * console.log(`${place.full_name}`);
1024
+ * console.log(`Type: ${place.place_type}`);
1025
+ * console.log(`Country: ${place.country}`);
1026
+ * ```
1027
+ */
1028
+ async getDetail(placeId) {
1029
+ return this.client.request(`/v1/twitter/geo/places/${placeId}`);
1030
+ }
1031
+ /**
1032
+ * Search for geographic places.
1033
+ *
1034
+ * At least one of lat/long, query, or ip must be provided.
1035
+ *
1036
+ * @param options - Search options.
1037
+ * @returns Paginated response containing matching places.
1038
+ * @throws ValidationError - If no search parameters are provided.
1039
+ *
1040
+ * @example
1041
+ * ```typescript
1042
+ * // Search by name
1043
+ * const places = await client.twitter.geo.search({ query: "San Francisco" });
1044
+ * for (const place of places.data) {
1045
+ * console.log(`${place.full_name} (${place.place_type})`);
1046
+ * }
1047
+ *
1048
+ * // Search by coordinates
1049
+ * const nearby = await client.twitter.geo.search({
1050
+ * lat: 37.7749,
1051
+ * long: -122.4194,
1052
+ * granularity: "city"
1053
+ * });
1054
+ *
1055
+ * // Search by IP
1056
+ * const ipPlaces = await client.twitter.geo.search({ ip: "8.8.8.8" });
1057
+ * ```
1058
+ */
1059
+ async search(options = {}) {
1060
+ const response = await this.client.request("/v1/twitter/geo/search", {
1061
+ params: {
1062
+ lat: options.lat,
1063
+ long: options.long,
1064
+ query: options.query,
1065
+ ip: options.ip,
1066
+ granularity: options.granularity,
1067
+ max_results: options.maxResults
1068
+ }
1069
+ });
1070
+ return createPaginatedResponse(response.data ?? []);
1071
+ }
1072
+ };
1073
+
1074
+ // src/twitter/client.ts
1075
+ var TwitterClient = class {
1076
+ /** Client for tweet operations */
1077
+ tweets;
1078
+ /** Client for user operations */
1079
+ users;
1080
+ /** Client for list operations */
1081
+ lists;
1082
+ /** Client for community operations */
1083
+ communities;
1084
+ /** Client for trends operations */
1085
+ trends;
1086
+ /** Client for geo/places operations */
1087
+ geo;
1088
+ /**
1089
+ * Create a new Twitter client.
1090
+ *
1091
+ * @param client - The base HTTP client for making requests.
1092
+ */
1093
+ constructor(client) {
1094
+ this.tweets = new TweetsClient(client);
1095
+ this.users = new UsersClient(client);
1096
+ this.lists = new ListsClient(client);
1097
+ this.communities = new CommunitiesClient(client);
1098
+ this.trends = new TrendsClient(client);
1099
+ this.geo = new GeoClient(client);
1100
+ }
1101
+ };
1102
+
1103
+ export { CommunitiesClient, GeoClient, ListsClient, TrendsClient, TweetsClient, TwitterClient, UsersClient };
1104
+ //# sourceMappingURL=index.mjs.map
1105
+ //# sourceMappingURL=index.mjs.map