@the-convocation/twitter-scraper 0.16.2 → 0.16.4

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.
@@ -49,13 +49,13 @@ class AuthenticationError extends Error {
49
49
  }
50
50
  }
51
51
 
52
- const log$2 = debug("twitter-scraper:rate-limit");
52
+ const log$3 = debug("twitter-scraper:rate-limit");
53
53
  class WaitingRateLimitStrategy {
54
54
  async onRateLimit({ response: res }) {
55
55
  const xRateLimitLimit = res.headers.get("x-rate-limit-limit");
56
56
  const xRateLimitRemaining = res.headers.get("x-rate-limit-remaining");
57
57
  const xRateLimitReset = res.headers.get("x-rate-limit-reset");
58
- log$2(
58
+ log$3(
59
59
  `Rate limit event: limit=${xRateLimitLimit}, remaining=${xRateLimitRemaining}, reset=${xRateLimitReset}`
60
60
  );
61
61
  if (xRateLimitRemaining == "0" && xRateLimitReset) {
@@ -108,14 +108,14 @@ async function updateCookieJar(cookieJar, headers) {
108
108
  }
109
109
  }
110
110
 
111
- const log$1 = debug("twitter-scraper:api");
111
+ const log$2 = debug("twitter-scraper:api");
112
112
  const bearerToken = "AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF";
113
113
  async function jitter(maxMs) {
114
114
  const jitter2 = Math.random() * maxMs;
115
115
  await new Promise((resolve) => setTimeout(resolve, jitter2));
116
116
  }
117
117
  async function requestApi(url, auth, method = "GET", platform = new Platform()) {
118
- log$1(`Making ${method} request to ${url}`);
118
+ log$2(`Making ${method} request to ${url}`);
119
119
  const headers = new Headers();
120
120
  await auth.installTo(headers, url);
121
121
  await platform.randomizeCiphers();
@@ -142,7 +142,7 @@ async function requestApi(url, auth, method = "GET", platform = new Platform())
142
142
  }
143
143
  await updateCookieJar(auth.cookieJar(), res.headers);
144
144
  if (res.status === 429) {
145
- log$1("Rate limit hit, waiting for retry...");
145
+ log$2("Rate limit hit, waiting for retry...");
146
146
  await auth.onRateLimit({
147
147
  fetchParameters,
148
148
  response: res
@@ -233,6 +233,7 @@ function addApiParams(params, includeTweetReplies) {
233
233
  return params;
234
234
  }
235
235
 
236
+ const log$1 = debug("twitter-scraper:auth");
236
237
  function withTransform(fetchFn, transform) {
237
238
  return async (input, init) => {
238
239
  const fetchArgs = await transform?.request?.(input, init) ?? [
@@ -336,6 +337,7 @@ class TwitterGuestAuth {
336
337
  Authorization: `Bearer ${this.bearerToken}`,
337
338
  Cookie: await this.getCookieString()
338
339
  });
340
+ log$1(`Making POST request to ${guestActivateUrl}`);
339
341
  const res = await this.fetch(guestActivateUrl, {
340
342
  method: "POST",
341
343
  headers,
@@ -686,6 +688,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
686
688
  if ("flow_name" in data) {
687
689
  onboardingTaskUrl = `https://api.x.com/1.1/onboarding/task.json?flow_name=${data.flow_name}`;
688
690
  }
691
+ log(`Making POST request to ${onboardingTaskUrl}`);
689
692
  const token = this.guestToken;
690
693
  if (token == null) {
691
694
  throw new AuthenticationError(
@@ -722,7 +725,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
722
725
  }
723
726
  return {
724
727
  status: "error",
725
- err: new Error("Failed to perform request.")
728
+ err
726
729
  };
727
730
  }
728
731
  await updateCookieJar(this.jar, res.headers);
@@ -1197,7 +1200,8 @@ function parseLegacyTweet(coreUser, user, tweet, editControl) {
1197
1200
  const parsedResult = parseLegacyTweet(
1198
1201
  retweetedStatusResult?.core?.user_results?.result?.core,
1199
1202
  retweetedStatusResult?.core?.user_results?.result?.legacy,
1200
- retweetedStatusResult?.legacy
1203
+ retweetedStatusResult?.legacy,
1204
+ retweetedStatusResult?.edit_control?.edit_control_initial
1201
1205
  );
1202
1206
  if (parsedResult.success) {
1203
1207
  tw.retweetedStatus = parsedResult.tweet;
@@ -1225,7 +1229,8 @@ function parseResult(result) {
1225
1229
  const tweetResult = parseLegacyTweet(
1226
1230
  result?.core?.user_results?.result?.core,
1227
1231
  result?.core?.user_results?.result?.legacy,
1228
- result?.legacy
1232
+ result?.legacy,
1233
+ result?.edit_control?.edit_control_initial
1229
1234
  );
1230
1235
  if (!tweetResult.success) {
1231
1236
  return tweetResult;
@@ -1253,7 +1258,7 @@ function parseTimelineTweetsV2(timeline) {
1253
1258
  let bottomCursor;
1254
1259
  let topCursor;
1255
1260
  const tweets = [];
1256
- const instructions = timeline.data?.user?.result?.timeline_v2?.timeline?.instructions ?? [];
1261
+ const instructions = timeline.data?.user?.result?.timeline?.timeline?.instructions ?? [];
1257
1262
  for (const instruction of instructions) {
1258
1263
  const entries = instruction.entries ?? [];
1259
1264
  for (const entry of entries) {