@the-convocation/twitter-scraper 0.20.2 → 0.20.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.
@@ -148,13 +148,13 @@ async function updateCookieJar(cookieJar, headers) {
148
148
 
149
149
  const log$4 = debug("twitter-scraper:xpff");
150
150
  let isoCrypto = null;
151
- function getCrypto() {
151
+ async function getCrypto() {
152
152
  if (isoCrypto != null) {
153
153
  return isoCrypto;
154
154
  }
155
155
  if (typeof crypto === "undefined") {
156
156
  log$4("Global crypto is undefined, importing from crypto module...");
157
- const { webcrypto } = require("crypto");
157
+ const { webcrypto } = await import('crypto');
158
158
  isoCrypto = webcrypto;
159
159
  return webcrypto;
160
160
  }
@@ -163,7 +163,8 @@ function getCrypto() {
163
163
  }
164
164
  async function sha256(message) {
165
165
  const msgBuffer = new TextEncoder().encode(message);
166
- const hashBuffer = await getCrypto().subtle.digest("SHA-256", msgBuffer);
166
+ const crypto2 = await getCrypto();
167
+ const hashBuffer = await crypto2.subtle.digest("SHA-256", msgBuffer);
167
168
  return new Uint8Array(hashBuffer);
168
169
  }
169
170
  function buf2hex(buffer) {
@@ -181,15 +182,16 @@ class XPFFHeaderGenerator {
181
182
  async generateHeader(plaintext, guestId) {
182
183
  log$4(`Generating XPFF key for guest ID: ${guestId}`);
183
184
  const key = await this.deriveKey(guestId);
184
- const nonce = getCrypto().getRandomValues(new Uint8Array(12));
185
- const cipher = await getCrypto().subtle.importKey(
185
+ const crypto2 = await getCrypto();
186
+ const nonce = crypto2.getRandomValues(new Uint8Array(12));
187
+ const cipher = await crypto2.subtle.importKey(
186
188
  "raw",
187
189
  key,
188
190
  { name: "AES-GCM" },
189
191
  false,
190
192
  ["encrypt"]
191
193
  );
192
- const encrypted = await getCrypto().subtle.encrypt(
194
+ const encrypted = await crypto2.subtle.encrypt(
193
195
  {
194
196
  name: "AES-GCM",
195
197
  iv: nonce
@@ -200,7 +202,7 @@ class XPFFHeaderGenerator {
200
202
  const combined = new Uint8Array(nonce.length + encrypted.byteLength);
201
203
  combined.set(nonce);
202
204
  combined.set(new Uint8Array(encrypted), nonce.length);
203
- const result = buf2hex(combined);
205
+ const result = buf2hex(combined.buffer);
204
206
  log$4(`XPFF header generated for guest ID ${guestId}: ${result}`);
205
207
  return result;
206
208
  }
@@ -404,9 +406,9 @@ class Platform {
404
406
 
405
407
  const log$2 = debug("twitter-scraper:xctxid");
406
408
  let linkedom = null;
407
- function linkedomImport() {
409
+ async function linkedomImport() {
408
410
  if (!linkedom) {
409
- const mod = require("linkedom");
411
+ const mod = await import('linkedom');
410
412
  linkedom = mod;
411
413
  return mod;
412
414
  }
@@ -420,7 +422,7 @@ async function parseHTML(html) {
420
422
  }
421
423
  return defaultView;
422
424
  } else {
423
- const { DOMParser: DOMParser2 } = linkedomImport();
425
+ const { DOMParser: DOMParser2 } = await linkedomImport();
424
426
  return new DOMParser2().parseFromString(html, "text/html").defaultView;
425
427
  }
426
428
  }
@@ -498,12 +500,11 @@ async function handleXMigration(fetchFn) {
498
500
  return document;
499
501
  }
500
502
  let ClientTransaction = null;
501
- function clientTransaction() {
503
+ async function clientTransaction() {
502
504
  if (!ClientTransaction) {
503
- const mod = require("x-client-transaction-id");
504
- const ctx = mod.ClientTransaction;
505
- ClientTransaction = ctx;
506
- return ctx;
505
+ const mod = await import('x-client-transaction-id');
506
+ ClientTransaction = mod.ClientTransaction;
507
+ return mod.ClientTransaction;
507
508
  }
508
509
  return ClientTransaction;
509
510
  }
@@ -512,7 +513,8 @@ async function generateTransactionId(url, fetchFn, method) {
512
513
  const path = parsedUrl.pathname;
513
514
  log$2(`Generating transaction ID for ${method} ${path}`);
514
515
  const document = await handleXMigration(fetchFn);
515
- const transaction = await clientTransaction().create(document);
516
+ const ClientTransactionClass = await clientTransaction();
517
+ const transaction = await ClientTransactionClass.create(document);
516
518
  const transactionId = await transaction.generateTransactionId(method, path);
517
519
  log$2(`Transaction ID: ${transactionId}`);
518
520
  return transactionId;