@the-convocation/twitter-scraper 0.16.2 → 0.16.3

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.
@@ -72,13 +72,13 @@ class AuthenticationError extends Error {
72
72
  }
73
73
  }
74
74
 
75
- const log$2 = debug("twitter-scraper:rate-limit");
75
+ const log$3 = debug("twitter-scraper:rate-limit");
76
76
  class WaitingRateLimitStrategy {
77
77
  async onRateLimit({ response: res }) {
78
78
  const xRateLimitLimit = res.headers.get("x-rate-limit-limit");
79
79
  const xRateLimitRemaining = res.headers.get("x-rate-limit-remaining");
80
80
  const xRateLimitReset = res.headers.get("x-rate-limit-reset");
81
- log$2(
81
+ log$3(
82
82
  `Rate limit event: limit=${xRateLimitLimit}, remaining=${xRateLimitRemaining}, reset=${xRateLimitReset}`
83
83
  );
84
84
  if (xRateLimitRemaining == "0" && xRateLimitReset) {
@@ -128,14 +128,14 @@ async function updateCookieJar(cookieJar, headers) {
128
128
  }
129
129
  }
130
130
 
131
- const log$1 = debug("twitter-scraper:api");
131
+ const log$2 = debug("twitter-scraper:api");
132
132
  const bearerToken = "AAAAAAAAAAAAAAAAAAAAAFQODgEAAAAAVHTp76lzh3rFzcHbmHVvQxYYpTw%3DckAlMINMjmCwxUcaXbAN4XqJVdgMJaHqNOFgPMK0zN1qLqLQCF";
133
133
  async function jitter(maxMs) {
134
134
  const jitter2 = Math.random() * maxMs;
135
135
  await new Promise((resolve) => setTimeout(resolve, jitter2));
136
136
  }
137
137
  async function requestApi(url, auth, method = "GET", platform = new Platform()) {
138
- log$1(`Making ${method} request to ${url}`);
138
+ log$2(`Making ${method} request to ${url}`);
139
139
  const headers = new headersPolyfill.Headers();
140
140
  await auth.installTo(headers, url);
141
141
  await platform.randomizeCiphers();
@@ -162,7 +162,7 @@ async function requestApi(url, auth, method = "GET", platform = new Platform())
162
162
  }
163
163
  await updateCookieJar(auth.cookieJar(), res.headers);
164
164
  if (res.status === 429) {
165
- log$1("Rate limit hit, waiting for retry...");
165
+ log$2("Rate limit hit, waiting for retry...");
166
166
  await auth.onRateLimit({
167
167
  fetchParameters,
168
168
  response: res
@@ -253,6 +253,7 @@ function addApiParams(params, includeTweetReplies) {
253
253
  return params;
254
254
  }
255
255
 
256
+ const log$1 = debug("twitter-scraper:auth");
256
257
  function withTransform(fetchFn, transform) {
257
258
  return async (input, init) => {
258
259
  const fetchArgs = await transform?.request?.(input, init) ?? [
@@ -356,6 +357,7 @@ class TwitterGuestAuth {
356
357
  Authorization: `Bearer ${this.bearerToken}`,
357
358
  Cookie: await this.getCookieString()
358
359
  });
360
+ log$1(`Making POST request to ${guestActivateUrl}`);
359
361
  const res = await this.fetch(guestActivateUrl, {
360
362
  method: "POST",
361
363
  headers,
@@ -706,6 +708,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
706
708
  if ("flow_name" in data) {
707
709
  onboardingTaskUrl = `https://api.x.com/1.1/onboarding/task.json?flow_name=${data.flow_name}`;
708
710
  }
711
+ log(`Making POST request to ${onboardingTaskUrl}`);
709
712
  const token = this.guestToken;
710
713
  if (token == null) {
711
714
  throw new AuthenticationError(
@@ -742,7 +745,7 @@ class TwitterUserAuth extends TwitterGuestAuth {
742
745
  }
743
746
  return {
744
747
  status: "error",
745
- err: new Error("Failed to perform request.")
748
+ err
746
749
  };
747
750
  }
748
751
  await updateCookieJar(this.jar, res.headers);
@@ -1273,7 +1276,7 @@ function parseTimelineTweetsV2(timeline) {
1273
1276
  let bottomCursor;
1274
1277
  let topCursor;
1275
1278
  const tweets = [];
1276
- const instructions = timeline.data?.user?.result?.timeline_v2?.timeline?.instructions ?? [];
1279
+ const instructions = timeline.data?.user?.result?.timeline?.timeline?.instructions ?? [];
1277
1280
  for (const instruction of instructions) {
1278
1281
  const entries = instruction.entries ?? [];
1279
1282
  for (const entry of entries) {