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