@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.
@@ -70,13 +70,13 @@ class AuthenticationError extends Error {
70
70
  }
71
71
  }
72
72
 
73
- const log$2 = debug("twitter-scraper:rate-limit");
73
+ const log$3 = debug("twitter-scraper:rate-limit");
74
74
  class WaitingRateLimitStrategy {
75
75
  async onRateLimit({ response: res }) {
76
76
  const xRateLimitLimit = res.headers.get("x-rate-limit-limit");
77
77
  const xRateLimitRemaining = res.headers.get("x-rate-limit-remaining");
78
78
  const xRateLimitReset = res.headers.get("x-rate-limit-reset");
79
- log$2(
79
+ log$3(
80
80
  `Rate limit event: limit=${xRateLimitLimit}, remaining=${xRateLimitRemaining}, reset=${xRateLimitReset}`
81
81
  );
82
82
  if (xRateLimitRemaining == "0" && xRateLimitReset) {
@@ -129,14 +129,14 @@ async function updateCookieJar(cookieJar, headers) {
129
129
  }
130
130
  }
131
131
 
132
- const log$1 = debug("twitter-scraper:api");
132
+ const log$2 = debug("twitter-scraper:api");
133
133
  const bearerToken = "AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF";
134
134
  async function jitter(maxMs) {
135
135
  const jitter2 = Math.random() * maxMs;
136
136
  await new Promise((resolve) => setTimeout(resolve, jitter2));
137
137
  }
138
138
  async function requestApi(url, auth, method = "GET", platform = new Platform()) {
139
- log$1(`Making ${method} request to ${url}`);
139
+ log$2(`Making ${method} request to ${url}`);
140
140
  const headers = new headersPolyfill.Headers();
141
141
  await auth.installTo(headers, url);
142
142
  await platform.randomizeCiphers();
@@ -163,7 +163,7 @@ async function requestApi(url, auth, method = "GET", platform = new Platform())
163
163
  }
164
164
  await updateCookieJar(auth.cookieJar(), res.headers);
165
165
  if (res.status === 429) {
166
- log$1("Rate limit hit, waiting for retry...");
166
+ log$2("Rate limit hit, waiting for retry...");
167
167
  await auth.onRateLimit({
168
168
  fetchParameters,
169
169
  response: res
@@ -254,6 +254,7 @@ function addApiParams(params, includeTweetReplies) {
254
254
  return params;
255
255
  }
256
256
 
257
+ const log$1 = debug("twitter-scraper:auth");
257
258
  function withTransform(fetchFn, transform) {
258
259
  return async (input, init) => {
259
260
  const fetchArgs = await transform?.request?.(input, init) ?? [
@@ -357,6 +358,7 @@ class TwitterGuestAuth {
357
358
  Authorization: `Bearer ${this.bearerToken}`,
358
359
  Cookie: await this.getCookieString()
359
360
  });
361
+ log$1(`Making POST request to ${guestActivateUrl}`);
360
362
  const res = await this.fetch(guestActivateUrl, {
361
363
  method: "POST",
362
364
  headers,
@@ -707,6 +709,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
707
709
  if ("flow_name" in data) {
708
710
  onboardingTaskUrl = `https://api.x.com/1.1/onboarding/task.json?flow_name=${data.flow_name}`;
709
711
  }
712
+ log(`Making POST request to ${onboardingTaskUrl}`);
710
713
  const token = this.guestToken;
711
714
  if (token == null) {
712
715
  throw new AuthenticationError(
@@ -743,7 +746,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
743
746
  }
744
747
  return {
745
748
  status: "error",
746
- err: new Error("Failed to perform request.")
749
+ err
747
750
  };
748
751
  }
749
752
  await updateCookieJar(this.jar, res.headers);
@@ -1218,7 +1221,8 @@ function parseLegacyTweet(coreUser, user, tweet, editControl) {
1218
1221
  const parsedResult = parseLegacyTweet(
1219
1222
  retweetedStatusResult?.core?.user_results?.result?.core,
1220
1223
  retweetedStatusResult?.core?.user_results?.result?.legacy,
1221
- retweetedStatusResult?.legacy
1224
+ retweetedStatusResult?.legacy,
1225
+ retweetedStatusResult?.edit_control?.edit_control_initial
1222
1226
  );
1223
1227
  if (parsedResult.success) {
1224
1228
  tw.retweetedStatus = parsedResult.tweet;
@@ -1246,7 +1250,8 @@ function parseResult(result) {
1246
1250
  const tweetResult = parseLegacyTweet(
1247
1251
  result?.core?.user_results?.result?.core,
1248
1252
  result?.core?.user_results?.result?.legacy,
1249
- result?.legacy
1253
+ result?.legacy,
1254
+ result?.edit_control?.edit_control_initial
1250
1255
  );
1251
1256
  if (!tweetResult.success) {
1252
1257
  return tweetResult;
@@ -1274,7 +1279,7 @@ function parseTimelineTweetsV2(timeline) {
1274
1279
  let bottomCursor;
1275
1280
  let topCursor;
1276
1281
  const tweets = [];
1277
- const instructions = timeline.data?.user?.result?.timeline_v2?.timeline?.instructions ?? [];
1282
+ const instructions = timeline.data?.user?.result?.timeline?.timeline?.instructions ?? [];
1278
1283
  for (const instruction of instructions) {
1279
1284
  const entries = instruction.entries ?? [];
1280
1285
  for (const entry of entries) {