@the-convocation/twitter-scraper 0.14.1 → 0.15.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 +32 -0
- package/dist/default/cjs/index.js +37 -11
- package/dist/default/cjs/index.js.map +1 -1
- package/dist/default/esm/index.mjs +35 -12
- package/dist/default/esm/index.mjs.map +1 -1
- package/dist/node/cjs/index.cjs +37 -11
- package/dist/node/cjs/index.cjs.map +1 -1
- package/dist/node/esm/index.mjs +35 -12
- package/dist/node/esm/index.mjs.map +1 -1
- package/dist/types/index.d.ts +66 -1
- package/package.json +2 -2
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Cookie } from 'tough-cookie';
|
|
|
2
2
|
import fetch from 'cross-fetch';
|
|
3
3
|
|
|
4
4
|
type FetchParameters = [input: RequestInfo | URL, init?: RequestInit];
|
|
5
|
+
|
|
5
6
|
interface FetchTransformOptions {
|
|
6
7
|
/**
|
|
7
8
|
* Transforms the request options before a request is made. This executes after all of the default
|
|
@@ -20,6 +21,66 @@ interface FetchTransformOptions {
|
|
|
20
21
|
response: (response: Response) => Response | Promise<Response>;
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
declare class ApiError extends Error {
|
|
25
|
+
readonly response: Response;
|
|
26
|
+
readonly data: any;
|
|
27
|
+
private constructor();
|
|
28
|
+
static fromResponse(response: Response): Promise<ApiError>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Information about a rate-limiting event. Both the request and response
|
|
33
|
+
* information are provided.
|
|
34
|
+
*/
|
|
35
|
+
interface RateLimitEvent {
|
|
36
|
+
/** The complete arguments that were passed to the fetch function. */
|
|
37
|
+
fetchParameters: FetchParameters;
|
|
38
|
+
/** The failing HTTP response. */
|
|
39
|
+
response: Response;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The public interface for all rate-limiting strategies. Library consumers are
|
|
43
|
+
* welcome to provide their own implementations of this interface in the Scraper
|
|
44
|
+
* constructor options.
|
|
45
|
+
*
|
|
46
|
+
* The {@link RateLimitEvent} object contains both the request and response
|
|
47
|
+
* information associated with the event.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* import { Scraper, RateLimitStrategy } from "@the-convocation/twitter-scraper";
|
|
51
|
+
*
|
|
52
|
+
* // A custom rate-limiting implementation that just logs request/response information.
|
|
53
|
+
* class ConsoleLogRateLimitStrategy implements RateLimitStrategy {
|
|
54
|
+
* async onRateLimit(event: RateLimitEvent): Promise<void> {
|
|
55
|
+
* console.log(event.fetchParameters, event.response);
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* const scraper = new Scraper({
|
|
60
|
+
* rateLimitStrategy: new ConsoleLogRateLimitStrategy(),
|
|
61
|
+
* });
|
|
62
|
+
*/
|
|
63
|
+
interface RateLimitStrategy {
|
|
64
|
+
/**
|
|
65
|
+
* Called when the scraper is rate limited.
|
|
66
|
+
* @param event The event information, including the request and response info.
|
|
67
|
+
*/
|
|
68
|
+
onRateLimit(event: RateLimitEvent): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A rate-limiting strategy that simply waits for the current rate limit period to expire.
|
|
72
|
+
* This has been known to take up to 13 minutes, in some cases.
|
|
73
|
+
*/
|
|
74
|
+
declare class WaitingRateLimitStrategy implements RateLimitStrategy {
|
|
75
|
+
onRateLimit({ response: res }: RateLimitEvent): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A rate-limiting strategy that throws an {@link ApiError} when a rate limiting event occurs.
|
|
79
|
+
*/
|
|
80
|
+
declare class ErrorRateLimitStrategy implements RateLimitStrategy {
|
|
81
|
+
onRateLimit({ response: res }: RateLimitEvent): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
|
|
23
84
|
interface LegacyUserRaw {
|
|
24
85
|
created_at?: string;
|
|
25
86
|
description?: string;
|
|
@@ -291,6 +352,10 @@ interface ScraperOptions {
|
|
|
291
352
|
* proxy requests through other hosts, for example.
|
|
292
353
|
*/
|
|
293
354
|
transform: Partial<FetchTransformOptions>;
|
|
355
|
+
/**
|
|
356
|
+
* A handling strategy for rate limits (HTTP 429).
|
|
357
|
+
*/
|
|
358
|
+
rateLimitStrategy: RateLimitStrategy;
|
|
294
359
|
}
|
|
295
360
|
/**
|
|
296
361
|
* An interface to Twitter's undocumented API.
|
|
@@ -533,4 +598,4 @@ declare class Scraper {
|
|
|
533
598
|
private handleResponse;
|
|
534
599
|
}
|
|
535
600
|
|
|
536
|
-
export { type Mention, type Photo, type PlaceRaw, type Profile, type QueryProfilesResponse, type QueryTweetsResponse, Scraper, SearchMode, type Tweet, type Video };
|
|
601
|
+
export { ApiError, ErrorRateLimitStrategy, type FetchParameters, type FetchTransformOptions, type Mention, type Photo, type PlaceRaw, type Profile, type QueryProfilesResponse, type QueryTweetsResponse, type RateLimitEvent, type RateLimitStrategy, Scraper, type ScraperOptions, SearchMode, type Tweet, type TweetQuery, type Video, WaitingRateLimitStrategy };
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"scraper",
|
|
8
8
|
"crawler"
|
|
9
9
|
],
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.15.0",
|
|
11
11
|
"main": "dist/default/cjs/index.js",
|
|
12
12
|
"types": "./dist/types/index.d.ts",
|
|
13
13
|
"exports": {
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"rollup-plugin-dts": "^6.1.1",
|
|
75
75
|
"rollup-plugin-esbuild": "^6.1.1",
|
|
76
76
|
"ts-jest": "^29.1.0",
|
|
77
|
-
"typedoc": "^0.
|
|
77
|
+
"typedoc": "^0.27.6",
|
|
78
78
|
"typescript": "^5.0.4"
|
|
79
79
|
},
|
|
80
80
|
"config": {
|