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