@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.
@@ -127,13 +127,13 @@ async function updateCookieJar(cookieJar, headers) {
127
127
 
128
128
  const log$4 = debug("twitter-scraper:xpff");
129
129
  let isoCrypto = null;
130
- function getCrypto() {
130
+ async function getCrypto() {
131
131
  if (isoCrypto != null) {
132
132
  return isoCrypto;
133
133
  }
134
134
  if (typeof crypto === "undefined") {
135
135
  log$4("Global crypto is undefined, importing from crypto module...");
136
- const { webcrypto } = require("crypto");
136
+ const { webcrypto } = await import('crypto');
137
137
  isoCrypto = webcrypto;
138
138
  return webcrypto;
139
139
  }
@@ -142,7 +142,8 @@ function getCrypto() {
142
142
  }
143
143
  async function sha256(message) {
144
144
  const msgBuffer = new TextEncoder().encode(message);
145
- const hashBuffer = await getCrypto().subtle.digest("SHA-256", msgBuffer);
145
+ const crypto2 = await getCrypto();
146
+ const hashBuffer = await crypto2.subtle.digest("SHA-256", msgBuffer);
146
147
  return new Uint8Array(hashBuffer);
147
148
  }
148
149
  function buf2hex(buffer) {
@@ -160,15 +161,16 @@ class XPFFHeaderGenerator {
160
161
  async generateHeader(plaintext, guestId) {
161
162
  log$4(`Generating XPFF key for guest ID: ${guestId}`);
162
163
  const key = await this.deriveKey(guestId);
163
- const nonce = getCrypto().getRandomValues(new Uint8Array(12));
164
- const cipher = await getCrypto().subtle.importKey(
164
+ const crypto2 = await getCrypto();
165
+ const nonce = crypto2.getRandomValues(new Uint8Array(12));
166
+ const cipher = await crypto2.subtle.importKey(
165
167
  "raw",
166
168
  key,
167
169
  { name: "AES-GCM" },
168
170
  false,
169
171
  ["encrypt"]
170
172
  );
171
- const encrypted = await getCrypto().subtle.encrypt(
173
+ const encrypted = await crypto2.subtle.encrypt(
172
174
  {
173
175
  name: "AES-GCM",
174
176
  iv: nonce
@@ -179,7 +181,7 @@ class XPFFHeaderGenerator {
179
181
  const combined = new Uint8Array(nonce.length + encrypted.byteLength);
180
182
  combined.set(nonce);
181
183
  combined.set(new Uint8Array(encrypted), nonce.length);
182
- const result = buf2hex(combined);
184
+ const result = buf2hex(combined.buffer);
183
185
  log$4(`XPFF header generated for guest ID ${guestId}: ${result}`);
184
186
  return result;
185
187
  }
@@ -383,9 +385,9 @@ class Platform {
383
385
 
384
386
  const log$2 = debug("twitter-scraper:xctxid");
385
387
  let linkedom = null;
386
- function linkedomImport() {
388
+ async function linkedomImport() {
387
389
  if (!linkedom) {
388
- const mod = require("linkedom");
390
+ const mod = await import('linkedom');
389
391
  linkedom = mod;
390
392
  return mod;
391
393
  }
@@ -399,7 +401,7 @@ async function parseHTML(html) {
399
401
  }
400
402
  return defaultView;
401
403
  } else {
402
- const { DOMParser: DOMParser2 } = linkedomImport();
404
+ const { DOMParser: DOMParser2 } = await linkedomImport();
403
405
  return new DOMParser2().parseFromString(html, "text/html").defaultView;
404
406
  }
405
407
  }
@@ -477,12 +479,11 @@ async function handleXMigration(fetchFn) {
477
479
  return document;
478
480
  }
479
481
  let ClientTransaction = null;
480
- function clientTransaction() {
482
+ async function clientTransaction() {
481
483
  if (!ClientTransaction) {
482
- const mod = require("x-client-transaction-id");
483
- const ctx = mod.ClientTransaction;
484
- ClientTransaction = ctx;
485
- return ctx;
484
+ const mod = await import('x-client-transaction-id');
485
+ ClientTransaction = mod.ClientTransaction;
486
+ return mod.ClientTransaction;
486
487
  }
487
488
  return ClientTransaction;
488
489
  }
@@ -491,7 +492,8 @@ async function generateTransactionId(url, fetchFn, method) {
491
492
  const path = parsedUrl.pathname;
492
493
  log$2(`Generating transaction ID for ${method} ${path}`);
493
494
  const document = await handleXMigration(fetchFn);
494
- const transaction = await clientTransaction().create(document);
495
+ const ClientTransactionClass = await clientTransaction();
496
+ const transaction = await ClientTransactionClass.create(document);
495
497
  const transactionId = await transaction.generateTransactionId(method, path);
496
498
  log$2(`Transaction ID: ${transactionId}`);
497
499
  return transactionId;