scrapebadger 0.3.1 → 0.7.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.
@@ -365,6 +365,59 @@ var TweetsClient = class {
365
365
  };
366
366
  yield* paginate(fetchPage, options);
367
367
  }
368
+ /**
369
+ * Get the edit history of a tweet.
370
+ *
371
+ * @param tweetId - The tweet ID to get edit history for.
372
+ * @returns Paginated response containing tweet versions.
373
+ *
374
+ * @example
375
+ * ```typescript
376
+ * const history = await client.twitter.tweets.getEditHistory("1234567890");
377
+ * console.log(`${history.data.length} version(s) of this tweet`);
378
+ * ```
379
+ */
380
+ async getEditHistory(tweetId) {
381
+ const response = await this.client.request(
382
+ `/v1/twitter/tweets/tweet/${tweetId}/edit_history`
383
+ );
384
+ return createPaginatedResponse(response.data ?? [], void 0);
385
+ }
386
+ /**
387
+ * Get community notes (Birdwatch) attached to a tweet.
388
+ *
389
+ * @param tweetId - The tweet ID to get community notes for.
390
+ * @returns Paginated response containing community notes.
391
+ *
392
+ * @example
393
+ * ```typescript
394
+ * const notes = await client.twitter.tweets.getCommunityNotes("1234567890");
395
+ * for (const note of notes.data) {
396
+ * console.log(note.text);
397
+ * }
398
+ * ```
399
+ */
400
+ async getCommunityNotes(tweetId) {
401
+ const response = await this.client.request(
402
+ `/v1/twitter/tweets/tweet/${tweetId}/community_notes`
403
+ );
404
+ return createPaginatedResponse(response.data ?? [], void 0);
405
+ }
406
+ /**
407
+ * Get a long-form article by its ID.
408
+ *
409
+ * @param articleId - The article ID to fetch.
410
+ * @returns The article data.
411
+ *
412
+ * @example
413
+ * ```typescript
414
+ * const article = await client.twitter.tweets.getArticle("abc123");
415
+ * console.log(`${article.title}: ${article.text?.slice(0, 100)}...`);
416
+ * ```
417
+ */
418
+ async getArticle(articleId) {
419
+ return this.client.request(`/v1/twitter/tweets/article/${articleId}`);
420
+ }
368
421
  };
369
422
 
370
423
  // src/twitter/users.ts
@@ -676,6 +729,92 @@ var UsersClient = class {
676
729
  };
677
730
  yield* paginate(fetchPage, options);
678
731
  }
732
+ /**
733
+ * Get multiple users by their numeric IDs in a single request.
734
+ *
735
+ * @param userIds - List of user IDs to fetch.
736
+ * @returns Paginated response containing the matching users.
737
+ *
738
+ * @example
739
+ * ```typescript
740
+ * const users = await client.twitter.users.getByIds(["44196397", "783214"]);
741
+ * for (const user of users.data) {
742
+ * console.log(`@${user.username}`);
743
+ * }
744
+ * ```
745
+ */
746
+ async getByIds(userIds) {
747
+ const response = await this.client.request(
748
+ "/v1/twitter/users/batch_by_ids",
749
+ { params: { user_ids: userIds.join(",") } }
750
+ );
751
+ return createPaginatedResponse(response.data ?? [], void 0);
752
+ }
753
+ /**
754
+ * Get multiple users by their usernames in a single request.
755
+ *
756
+ * @param usernames - List of usernames (without @) to fetch.
757
+ * @returns Paginated response containing the matching users.
758
+ *
759
+ * @example
760
+ * ```typescript
761
+ * const users = await client.twitter.users.getByUsernames(["elonmusk", "twitter"]);
762
+ * for (const user of users.data) {
763
+ * console.log(`${user.name}: ${user.followers_count?.toLocaleString()} followers`);
764
+ * }
765
+ * ```
766
+ */
767
+ async getByUsernames(usernames) {
768
+ const response = await this.client.request(
769
+ "/v1/twitter/users/batch_by_usernames",
770
+ { params: { usernames: usernames.join(",") } }
771
+ );
772
+ return createPaginatedResponse(response.data ?? [], void 0);
773
+ }
774
+ /**
775
+ * Get tweets that mention a user.
776
+ *
777
+ * @param username - The user's username (without @).
778
+ * @param options - Pagination options with optional count.
779
+ * @returns Paginated response containing tweets mentioning the user.
780
+ *
781
+ * @example
782
+ * ```typescript
783
+ * const mentions = await client.twitter.users.getMentions("elonmusk");
784
+ * for (const tweet of mentions.data) {
785
+ * console.log(`@${tweet.username}: ${tweet.text.slice(0, 100)}...`);
786
+ * }
787
+ * ```
788
+ */
789
+ async getMentions(username, options = {}) {
790
+ const response = await this.client.request(
791
+ `/v1/twitter/users/${username}/mentions`,
792
+ { params: { count: options.count, cursor: options.cursor } }
793
+ );
794
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
795
+ }
796
+ /**
797
+ * Get long-form articles authored by a user.
798
+ *
799
+ * @param userId - The user's numeric ID.
800
+ * @param options - Pagination options with optional count.
801
+ * @returns Paginated response containing the user's articles as tweets.
802
+ *
803
+ * @example
804
+ * ```typescript
805
+ * const articles = await client.twitter.users.getArticles("44196397");
806
+ * for (const article of articles.data) {
807
+ * console.log(article.text?.slice(0, 100));
808
+ * }
809
+ * ```
810
+ */
811
+ async getArticles(userId, options = {}) {
812
+ const response = await this.client.request(
813
+ `/v1/twitter/users/${userId}/articles`,
814
+ { params: { count: options.count, cursor: options.cursor } }
815
+ );
816
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
817
+ }
679
818
  };
680
819
 
681
820
  // src/twitter/lists.ts
@@ -822,6 +961,29 @@ var ListsClient = class {
822
961
  );
823
962
  return createPaginatedResponse(response.data ?? [], response.next_cursor);
824
963
  }
964
+ /**
965
+ * Search tweets within a specific list.
966
+ *
967
+ * @param listId - The list ID to search within.
968
+ * @param query - Search query string.
969
+ * @param options - Pagination options with optional count.
970
+ * @returns Paginated response containing matching tweets from the list.
971
+ *
972
+ * @example
973
+ * ```typescript
974
+ * const results = await client.twitter.lists.searchTweets("123456", "python");
975
+ * for (const tweet of results.data) {
976
+ * console.log(`@${tweet.username}: ${tweet.text.slice(0, 100)}...`);
977
+ * }
978
+ * ```
979
+ */
980
+ async searchTweets(listId, query, options = {}) {
981
+ const response = await this.client.request(
982
+ `/v1/twitter/lists/${listId}/search_tweets`,
983
+ { params: { query, count: options.count, cursor: options.cursor } }
984
+ );
985
+ return createPaginatedResponse(response.data ?? [], response.next_cursor);
986
+ }
825
987
  };
826
988
 
827
989
  // src/twitter/communities.ts
@@ -1706,7 +1868,7 @@ var StreamClient = class {
1706
1868
  return;
1707
1869
  }
1708
1870
  if (!reconnect) {
1709
- const reasonStr = reason instanceof Buffer ? reason.toString() : String(reason ?? "");
1871
+ const reasonStr = reason instanceof Buffer ? reason.toString() : typeof reason === "string" ? reason : "";
1710
1872
  emitter.emit(
1711
1873
  "error",
1712
1874
  new WebSocketStreamError(`WebSocket closed: ${reasonStr || String(code)}`)
@@ -1864,6 +2026,46 @@ function verifyWebhookSignature(secret, body, signatureHeader) {
1864
2026
  }
1865
2027
  }
1866
2028
 
2029
+ // src/twitter/spaces.ts
2030
+ var SpacesClient = class {
2031
+ client;
2032
+ constructor(client) {
2033
+ this.client = client;
2034
+ }
2035
+ /**
2036
+ * Get details for a specific Twitter Space.
2037
+ *
2038
+ * @param spaceId - The Space ID to fetch.
2039
+ * @returns The Space data.
2040
+ * @throws NotFoundError - If the Space doesn't exist.
2041
+ *
2042
+ * @example
2043
+ * ```typescript
2044
+ * const space = await client.twitter.spaces.getDetail("1eaKbrPPbPwKX");
2045
+ * console.log(`${space.title} — ${space.participant_count} participants`);
2046
+ * ```
2047
+ */
2048
+ async getDetail(spaceId) {
2049
+ return this.client.request(`/v1/twitter/spaces/${spaceId}`);
2050
+ }
2051
+ /**
2052
+ * Get details for a live video broadcast.
2053
+ *
2054
+ * @param broadcastId - The broadcast ID to fetch.
2055
+ * @returns The broadcast data.
2056
+ * @throws NotFoundError - If the broadcast doesn't exist.
2057
+ *
2058
+ * @example
2059
+ * ```typescript
2060
+ * const broadcast = await client.twitter.spaces.getBroadcast("broadcast123");
2061
+ * console.log(`${broadcast.title}: ${broadcast.total_viewers} viewers`);
2062
+ * ```
2063
+ */
2064
+ async getBroadcast(broadcastId) {
2065
+ return this.client.request(`/v1/twitter/spaces/broadcast/${broadcastId}`);
2066
+ }
2067
+ };
2068
+
1867
2069
  // src/twitter/client.ts
1868
2070
  var TwitterClient = class {
1869
2071
  /** Client for tweet operations */
@@ -1880,6 +2082,8 @@ var TwitterClient = class {
1880
2082
  geo;
1881
2083
  /** Client for real-time stream monitor management and WebSocket streaming */
1882
2084
  stream;
2085
+ /** Client for Twitter Spaces and live broadcast operations */
2086
+ spaces;
1883
2087
  /**
1884
2088
  * Create a new Twitter client.
1885
2089
  *
@@ -1893,9 +2097,10 @@ var TwitterClient = class {
1893
2097
  this.trends = new TrendsClient(client);
1894
2098
  this.geo = new GeoClient(client);
1895
2099
  this.stream = new StreamClient(client);
2100
+ this.spaces = new SpacesClient(client);
1896
2101
  }
1897
2102
  };
1898
2103
 
1899
- export { CommunitiesClient, GeoClient, ListsClient, StreamClient, TrendsClient, TweetsClient, TwitterClient, UsersClient, verifyWebhookSignature };
2104
+ export { CommunitiesClient, GeoClient, ListsClient, SpacesClient, StreamClient, TrendsClient, TweetsClient, TwitterClient, UsersClient, verifyWebhookSignature };
1900
2105
  //# sourceMappingURL=index.mjs.map
1901
2106
  //# sourceMappingURL=index.mjs.map