scrapebadger 0.78.0 → 0.80.0
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/README.md +86 -3
- package/dist/{index-D029O2qo.d.cts → index-BGPGvrzY.d.cts} +143 -31
- package/dist/{index-D029O2qo.d.ts → index-BGPGvrzY.d.ts} +143 -31
- package/dist/index.cjs +424 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +356 -64
- package/dist/index.d.ts +356 -64
- package/dist/index.mjs +423 -98
- package/dist/index.mjs.map +1 -1
- package/dist/twitter/index.cjs +25 -14
- package/dist/twitter/index.cjs.map +1 -1
- package/dist/twitter/index.d.cts +1 -1
- package/dist/twitter/index.d.ts +1 -1
- package/dist/twitter/index.mjs +25 -14
- package/dist/twitter/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/twitter/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var crypto = require('crypto');
|
|
4
3
|
var events = require('events');
|
|
5
4
|
var WebSocket = require('ws');
|
|
5
|
+
var crypto = require('crypto');
|
|
6
6
|
|
|
7
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
8
|
|
|
@@ -1368,6 +1368,30 @@ var WebSocketStreamError = class _WebSocketStreamError extends ScrapeBadgerError
|
|
|
1368
1368
|
Object.setPrototypeOf(this, _WebSocketStreamError.prototype);
|
|
1369
1369
|
}
|
|
1370
1370
|
};
|
|
1371
|
+
var DEFAULT_TOLERANCE_S = 300;
|
|
1372
|
+
var SIGNATURE_RE = /^sha256=([0-9a-fA-F]{64})$/;
|
|
1373
|
+
function rawBytes(rawBody, fn) {
|
|
1374
|
+
if (typeof rawBody === "string") return Buffer.from(rawBody, "utf-8");
|
|
1375
|
+
if (rawBody instanceof Uint8Array) {
|
|
1376
|
+
return Buffer.from(rawBody.buffer, rawBody.byteOffset, rawBody.byteLength);
|
|
1377
|
+
}
|
|
1378
|
+
if (rawBody instanceof ArrayBuffer) return Buffer.from(rawBody);
|
|
1379
|
+
throw new TypeError(
|
|
1380
|
+
`${fn} needs the raw request body (a string or Buffer) exactly as received, not a parsed object: read it with express.raw({ type: "application/json" }) or equivalent.`
|
|
1381
|
+
);
|
|
1382
|
+
}
|
|
1383
|
+
function verifyWebhookSignature(secret, rawBody, signature, options = {}) {
|
|
1384
|
+
const body = rawBytes(rawBody, "verifyWebhookSignature");
|
|
1385
|
+
if (!secret || typeof signature !== "string") return false;
|
|
1386
|
+
const match = SIGNATURE_RE.exec(signature.trim());
|
|
1387
|
+
if (!match?.[1]) return false;
|
|
1388
|
+
const expected = crypto.createHmac("sha256", secret).update(body).digest();
|
|
1389
|
+
if (!crypto.timingSafeEqual(expected, Buffer.from(match[1], "hex"))) return false;
|
|
1390
|
+
const { sentAt, toleranceS = DEFAULT_TOLERANCE_S } = options;
|
|
1391
|
+
if (sentAt === void 0 || sentAt === null) return true;
|
|
1392
|
+
const sentAtS = typeof sentAt === "number" ? sentAt : Number(sentAt.trim() || Number.NaN);
|
|
1393
|
+
return Math.abs(Date.now() / 1e3 - sentAtS) <= toleranceS;
|
|
1394
|
+
}
|
|
1371
1395
|
|
|
1372
1396
|
// src/twitter/stream.ts
|
|
1373
1397
|
var MIN_RECONNECT_DELAY_SECONDS = 5;
|
|
@@ -2048,19 +2072,6 @@ var StreamClient = class {
|
|
|
2048
2072
|
}
|
|
2049
2073
|
}
|
|
2050
2074
|
};
|
|
2051
|
-
function verifyWebhookSignature(secret, body, signatureHeader) {
|
|
2052
|
-
if (!signatureHeader.startsWith("sha256=")) {
|
|
2053
|
-
return false;
|
|
2054
|
-
}
|
|
2055
|
-
const expectedHex = signatureHeader.slice("sha256=".length);
|
|
2056
|
-
const bodyBuffer = typeof body === "string" ? Buffer.from(body, "utf-8") : body;
|
|
2057
|
-
const actualHex = crypto.createHmac("sha256", secret).update(bodyBuffer).digest("hex");
|
|
2058
|
-
try {
|
|
2059
|
-
return crypto.timingSafeEqual(Buffer.from(expectedHex, "hex"), Buffer.from(actualHex, "hex"));
|
|
2060
|
-
} catch {
|
|
2061
|
-
return false;
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
2075
|
|
|
2065
2076
|
// src/twitter/spaces.ts
|
|
2066
2077
|
var SpacesClient = class {
|