@the-convocation/twitter-scraper 0.22.2 → 0.22.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.
@@ -1366,7 +1366,7 @@ async function jitter(maxMs) {
1366
1366
  const jitter2 = Math.random() * maxMs;
1367
1367
  await new Promise((resolve) => setTimeout(resolve, jitter2));
1368
1368
  }
1369
- async function requestApi(url, auth, method = "GET", platform = new Platform(), headers = new headersPolyfill.Headers(), bearerTokenOverride) {
1369
+ async function requestApi(url, auth, method = "GET", platform = new Platform(), headers = new headersPolyfill.Headers(), bearerTokenOverride, body) {
1370
1370
  log$2(`Making ${method} request to ${url}`);
1371
1371
  await auth.installTo(headers, url, bearerTokenOverride);
1372
1372
  await platform.randomizeCiphers();
@@ -1378,6 +1378,9 @@ async function requestApi(url, auth, method = "GET", platform = new Platform(),
1378
1378
  );
1379
1379
  headers.set("x-client-transaction-id", transactionId);
1380
1380
  }
1381
+ if (body && method === "POST") {
1382
+ headers.set("content-type", "application/json");
1383
+ }
1381
1384
  let res;
1382
1385
  do {
1383
1386
  const fetchParameters = [
@@ -1385,7 +1388,8 @@ async function requestApi(url, auth, method = "GET", platform = new Platform(),
1385
1388
  {
1386
1389
  method,
1387
1390
  headers,
1388
- credentials: "include"
1391
+ credentials: "include",
1392
+ ...body && method === "POST" ? { body: JSON.stringify(body) } : {}
1389
1393
  }
1390
1394
  ];
1391
1395
  try {
@@ -2238,6 +2242,16 @@ class ApiRequest {
2238
2242
  }
2239
2243
  return `${this.url}?${params.toString()}`;
2240
2244
  }
2245
+ /**
2246
+ * Converts the request into a JSON body for POST requests.
2247
+ */
2248
+ toRequestBody() {
2249
+ const body = {};
2250
+ if (this.variables) body.variables = this.variables;
2251
+ if (this.features) body.features = this.features;
2252
+ if (this.fieldToggles) body.fieldToggles = this.fieldToggles;
2253
+ return body;
2254
+ }
2241
2255
  }
2242
2256
  function parseEndpointExample(example) {
2243
2257
  const { protocol, host, pathname, searchParams: query } = new URL(example);
@@ -2971,12 +2985,13 @@ async function getSearchTimeline(query, maxItems, searchMode, auth, cursor) {
2971
2985
  break;
2972
2986
  }
2973
2987
  const res = await requestApi(
2974
- searchTimelineRequest.toRequestUrl(),
2988
+ searchTimelineRequest.url,
2975
2989
  auth,
2976
- "GET",
2990
+ "POST",
2977
2991
  void 0,
2978
2992
  void 0,
2979
- bearerToken2
2993
+ bearerToken2,
2994
+ searchTimelineRequest.toRequestBody()
2980
2995
  );
2981
2996
  if (!res.success) {
2982
2997
  throw res.err;