@crawlee/types 4.0.0-beta.8 → 4.0.0-beta.81
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 +17 -13
- package/browser.d.ts +104 -1
- package/browser.js +0 -1
- package/http-client.d.ts +77 -0
- package/http-client.js +1 -0
- package/index.d.ts +7 -4
- package/index.js +1 -4
- package/logger.d.ts +66 -0
- package/logger.js +1 -0
- package/package.json +4 -3
- package/session.d.ts +150 -0
- package/session.js +1 -0
- package/status-message.d.ts +13 -0
- package/status-message.js +1 -0
- package/storages.d.ts +291 -167
- package/storages.js +0 -1
- package/utility-types.d.ts +1 -2
- package/utility-types.js +0 -1
- package/browser.d.ts.map +0 -1
- package/browser.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/storages.d.ts.map +0 -1
- package/storages.js.map +0 -1
- package/tsconfig.build.tsbuildinfo +0 -1
- package/utility-types.d.ts.map +0 -1
- package/utility-types.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
<h1 align="center">
|
|
2
2
|
<a href="https://crawlee.dev">
|
|
3
3
|
<picture>
|
|
4
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-dark.svg?sanitize=true"
|
|
5
|
-
<img alt="Crawlee" src="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-light.svg?sanitize=true" width="500"
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-dark.svg?sanitize=true" />
|
|
5
|
+
<img alt="Crawlee" src="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-light.svg?sanitize=true" width="500" />
|
|
6
6
|
</picture>
|
|
7
7
|
</a>
|
|
8
|
-
<br
|
|
8
|
+
<br />
|
|
9
9
|
<small>A web scraping and browser automation library</small>
|
|
10
10
|
</h1>
|
|
11
11
|
|
|
12
|
-
<p align=center>
|
|
13
|
-
<a href="https://
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
<p align="center">
|
|
13
|
+
<a href="https://trendshift.io/repositories/5179" target="_blank"><img src="https://trendshift.io/api/badge/repositories/5179" alt="apify%2Fcrawlee | Trendshift" width="250" height="55"/></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/v/@crawlee/core.svg" alt="NPM latest version" data-canonical-src="https://img.shields.io/npm/v/@crawlee/core/next.svg" /></a>
|
|
18
|
+
<a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/dm/@crawlee/core.svg" alt="Downloads" data-canonical-src="https://img.shields.io/npm/dm/@crawlee/core.svg" /></a>
|
|
19
|
+
<a href="https://discord.gg/jyEM2PRvMU" rel="nofollow"><img src="https://img.shields.io/discord/801163717915574323?label=discord" alt="Chat on discord" data-canonical-src="https://img.shields.io/discord/801163717915574323?label=discord" /></a>
|
|
20
|
+
<a href="https://github.com/apify/crawlee/actions/workflows/test-ci.yml"><img src="https://github.com/apify/crawlee/actions/workflows/test-ci.yml/badge.svg?branch=master" alt="Build Status" /></a>
|
|
17
21
|
</p>
|
|
18
22
|
|
|
19
23
|
Crawlee covers your crawling and scraping end-to-end and **helps you build reliable scrapers. Fast.**
|
|
@@ -24,7 +28,7 @@ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) N
|
|
|
24
28
|
|
|
25
29
|
> 👉 **View full documentation, guides and examples on the [Crawlee project website](https://crawlee.dev)** 👈
|
|
26
30
|
|
|
27
|
-
>
|
|
31
|
+
> Do you prefer 🐍 Python instead of JavaScript? [👉 Checkout Crawlee for Python 👈](https://github.com/apify/crawlee-python).
|
|
28
32
|
|
|
29
33
|
## Installation
|
|
30
34
|
|
|
@@ -85,7 +89,7 @@ By default, Crawlee stores data to `./storage` in the current working directory.
|
|
|
85
89
|
We provide automated beta builds for every merged code change in Crawlee. You can find them in the npm [list of releases](https://www.npmjs.com/package/crawlee?activeTab=versions). If you want to test new features or bug fixes before we release them, feel free to install a beta build like this:
|
|
86
90
|
|
|
87
91
|
```bash
|
|
88
|
-
npm install crawlee@
|
|
92
|
+
npm install crawlee@next
|
|
89
93
|
```
|
|
90
94
|
|
|
91
95
|
If you also use the [Apify SDK](https://github.com/apify/apify-sdk-js), you need to specify dependency overrides in your `package.json` file so that you don't end up with multiple versions of Crawlee installed:
|
|
@@ -94,9 +98,9 @@ If you also use the [Apify SDK](https://github.com/apify/apify-sdk-js), you need
|
|
|
94
98
|
{
|
|
95
99
|
"overrides": {
|
|
96
100
|
"apify": {
|
|
97
|
-
"@crawlee/core": "
|
|
98
|
-
"@crawlee/types": "
|
|
99
|
-
"@crawlee/utils": "
|
|
101
|
+
"@crawlee/core": "$crawlee",
|
|
102
|
+
"@crawlee/types": "$crawlee",
|
|
103
|
+
"@crawlee/utils": "$crawlee"
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
}
|
package/browser.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ISession } from './session.js';
|
|
1
2
|
import type { Dictionary } from './utility-types.js';
|
|
2
3
|
export interface Cookie {
|
|
3
4
|
/**
|
|
@@ -60,4 +61,106 @@ export interface BrowserLikeResponse {
|
|
|
60
61
|
url(): string;
|
|
61
62
|
headers(): Dictionary<string | string[]>;
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
+
/**
|
|
65
|
+
* A snapshot of the relevant state of a page, as extracted by
|
|
66
|
+
* {@link IBrowserPool.extractPageState}.
|
|
67
|
+
*/
|
|
68
|
+
export interface PageState {
|
|
69
|
+
/**
|
|
70
|
+
* Cookies currently set in the page's browsing context.
|
|
71
|
+
*/
|
|
72
|
+
cookies: Cookie[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Options accepted by {@link IBrowserPool.newPage}.
|
|
76
|
+
*/
|
|
77
|
+
export interface NewPageOptions {
|
|
78
|
+
/**
|
|
79
|
+
* Assign a custom ID to the page. If you don't provide one, a random string
|
|
80
|
+
* ID is generated.
|
|
81
|
+
*/
|
|
82
|
+
id?: string;
|
|
83
|
+
/**
|
|
84
|
+
* The crawling session that will use the returned page.
|
|
85
|
+
*
|
|
86
|
+
* The pool derives proxy configuration from the session's {@link
|
|
87
|
+
* ProxyInfo|proxy} (including TLS-error handling) — there are intentionally
|
|
88
|
+
* no standalone `proxyUrl` / `ignoreTlsErrors` options; configure them
|
|
89
|
+
* through the session instead.
|
|
90
|
+
*
|
|
91
|
+
* Session injection is **best-effort**: the pool may use the session's
|
|
92
|
+
* {@link ProxyInfo|proxy}, cookies, or fingerprint data to configure the
|
|
93
|
+
* page or the underlying browser, but none of this is guaranteed. Different
|
|
94
|
+
* pool implementations (or pool configurations such as `useIncognitoPages`)
|
|
95
|
+
* may support different subsets of session properties — or ignore them
|
|
96
|
+
* entirely.
|
|
97
|
+
*
|
|
98
|
+
* The crawler is still responsible for deterministic session setup (e.g.
|
|
99
|
+
* injecting cookies into the page before navigation) that must happen
|
|
100
|
+
* regardless of pool implementation.
|
|
101
|
+
*/
|
|
102
|
+
session?: ISession;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Minimal contract that any object passed to a browser crawler as its `browserPool`
|
|
106
|
+
* option must satisfy.
|
|
107
|
+
*
|
|
108
|
+
* Lifecycle (`destroy`) is the responsibility of whoever owns the pool — since a
|
|
109
|
+
* user-supplied pool is never owned by the crawler, the crawler never tears it
|
|
110
|
+
* down.
|
|
111
|
+
*
|
|
112
|
+
* Implement this interface to plug a custom page-provisioning strategy into any
|
|
113
|
+
* Crawlee browser crawler — for example a remote browser farm, a session-aware
|
|
114
|
+
* pool that pins pages to fingerprints differently, or a thin wrapper around the
|
|
115
|
+
* built-in `BrowserPool`.
|
|
116
|
+
*
|
|
117
|
+
* @category Browser management
|
|
118
|
+
*/
|
|
119
|
+
export interface IBrowserPool<Page = unknown> {
|
|
120
|
+
/**
|
|
121
|
+
* Opens a new page. The pool decides which browser to use, launching a new
|
|
122
|
+
* one if needed.
|
|
123
|
+
*/
|
|
124
|
+
newPage(options?: NewPageOptions): Promise<Page>;
|
|
125
|
+
/**
|
|
126
|
+
* Signals the pool that the caller is done with the page. The pool is
|
|
127
|
+
* responsible for closing the page and performing any necessary cleanup
|
|
128
|
+
* (e.g. retiring the underlying browser when a session has gone bad).
|
|
129
|
+
*
|
|
130
|
+
* @param page The page to release back to the pool.
|
|
131
|
+
* @param options.error If the page is being released because of an error,
|
|
132
|
+
* pass the error here. In particular, if the error is a
|
|
133
|
+
* {@link SessionError}, implementations should treat it as a signal
|
|
134
|
+
* to purge all state associated with the session (e.g. discard any
|
|
135
|
+
* browser that served the page).
|
|
136
|
+
*/
|
|
137
|
+
closePage(page: Page, options?: {
|
|
138
|
+
error?: Error;
|
|
139
|
+
}): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Extracts the relevant state from a page so the caller can persist it —
|
|
142
|
+
* for example, back-propagating cookies into the crawling {@link
|
|
143
|
+
* ISession|session}.
|
|
144
|
+
*
|
|
145
|
+
* @param page The page to read state from.
|
|
146
|
+
*/
|
|
147
|
+
extractPageState(page: Page): Promise<PageState>;
|
|
148
|
+
/**
|
|
149
|
+
* Injects state (currently just cookies) into a page. This is the
|
|
150
|
+
* counterpart to {@link IBrowserPool.extractPageState} and lets the
|
|
151
|
+
* caller set up a page — for example, seeding it with the crawling
|
|
152
|
+
* {@link ISession|session}'s cookies before navigation.
|
|
153
|
+
*
|
|
154
|
+
* As with {@link IBrowserPool.newPage}, the caller decides *what* state
|
|
155
|
+
* to inject, while the pool decides *how*.
|
|
156
|
+
*
|
|
157
|
+
* Isolation between pages is **best-effort**: depending on the pool
|
|
158
|
+
* implementation and its configuration, multiple pages may share a browsing
|
|
159
|
+
* context, so injected state (such as cookies) can bleed across pages
|
|
160
|
+
* served by the same underlying browser.
|
|
161
|
+
*
|
|
162
|
+
* @param page The page to inject state into.
|
|
163
|
+
* @param state The state to inject.
|
|
164
|
+
*/
|
|
165
|
+
injectPageState(page: Page, state: PageState): Promise<void>;
|
|
166
|
+
}
|
package/browser.js
CHANGED
package/http-client.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
import type { CookieJar } from 'tough-cookie';
|
|
3
|
+
import type { ISession } from './session.js';
|
|
4
|
+
import type { AllowedHttpMethods } from './utility-types.js';
|
|
5
|
+
export type SearchParams = string | URLSearchParams | Record<string, string | number | boolean | null | undefined>;
|
|
6
|
+
/**
|
|
7
|
+
* HTTP Request as accepted by {@link BaseHttpClient} methods.
|
|
8
|
+
*/
|
|
9
|
+
export interface HttpRequest {
|
|
10
|
+
url: string | URL;
|
|
11
|
+
method?: AllowedHttpMethods;
|
|
12
|
+
headers?: Headers;
|
|
13
|
+
body?: Readable;
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
cookieJar?: CookieJar;
|
|
17
|
+
followRedirect?: boolean | ((response: any) => boolean);
|
|
18
|
+
maxRedirects?: number;
|
|
19
|
+
encoding?: BufferEncoding;
|
|
20
|
+
throwHttpErrors?: boolean;
|
|
21
|
+
proxyUrl?: string;
|
|
22
|
+
headerGeneratorOptions?: Record<string, unknown>;
|
|
23
|
+
useHeaderGenerator?: boolean;
|
|
24
|
+
headerGenerator?: {
|
|
25
|
+
getHeaders: (options: Record<string, unknown>) => Record<string, string>;
|
|
26
|
+
};
|
|
27
|
+
insecureHTTPParser?: boolean;
|
|
28
|
+
sessionToken?: object;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Additional options for HTTP requests that need to be handled separately before passing to {@link BaseHttpClient}.
|
|
32
|
+
*/
|
|
33
|
+
export interface HttpRequestOptions extends HttpRequest {
|
|
34
|
+
/** Search (query string) parameters to be appended to the request URL */
|
|
35
|
+
searchParams?: SearchParams;
|
|
36
|
+
/** A form to be sent in the HTTP request body (URL encoding will be used) */
|
|
37
|
+
form?: Record<string, string>;
|
|
38
|
+
/** Arbitrary object to be JSON-serialized and sent as the HTTP request body */
|
|
39
|
+
json?: unknown;
|
|
40
|
+
/** Basic HTTP Auth username */
|
|
41
|
+
username?: string;
|
|
42
|
+
/** Basic HTTP Auth password */
|
|
43
|
+
password?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Type of a function called when an HTTP redirect takes place. It is allowed to mutate the `updatedRequest` argument.
|
|
47
|
+
*/
|
|
48
|
+
export type RedirectHandler = (redirectResponse: Response, updatedRequest: {
|
|
49
|
+
url?: string | URL;
|
|
50
|
+
headers: Headers;
|
|
51
|
+
}) => void;
|
|
52
|
+
export interface SendRequestOptions {
|
|
53
|
+
session?: ISession;
|
|
54
|
+
cookieJar?: CookieJar;
|
|
55
|
+
/** Timeout for the HTTP request in milliseconds. */
|
|
56
|
+
timeoutMillis?: number;
|
|
57
|
+
/** An AbortSignal to cancel the HTTP request. */
|
|
58
|
+
signal?: AbortSignal;
|
|
59
|
+
/**
|
|
60
|
+
* Overrides the proxy URL set in the `session` for this request.
|
|
61
|
+
*
|
|
62
|
+
* Note that setting this manually can interfere with session proxy rotation.
|
|
63
|
+
*/
|
|
64
|
+
proxyUrl?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface StreamOptions extends SendRequestOptions {
|
|
67
|
+
onRedirect?: RedirectHandler;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Interface for user-defined HTTP clients to be used for plain HTTP crawling and for sending additional requests during a crawl.
|
|
71
|
+
*/
|
|
72
|
+
export interface BaseHttpClient {
|
|
73
|
+
/**
|
|
74
|
+
* Perform an HTTP Request and return the complete response.
|
|
75
|
+
*/
|
|
76
|
+
sendRequest(request: Request, options?: SendRequestOptions): Promise<Response>;
|
|
77
|
+
}
|
package/http-client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
|
|
1
|
+
export type * from './status-message.js';
|
|
2
|
+
export type * from './storages.js';
|
|
3
|
+
export type * from './utility-types.js';
|
|
4
|
+
export type * from './browser.js';
|
|
5
|
+
export type * from './http-client.js';
|
|
6
|
+
export type * from './session.js';
|
|
7
|
+
export type * from './logger.js';
|
package/index.js
CHANGED
package/logger.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for Crawlee logger implementations.
|
|
3
|
+
*/
|
|
4
|
+
export interface CrawleeLoggerOptions {
|
|
5
|
+
/** Prefix to be prepended to each logged line. */
|
|
6
|
+
prefix?: string | null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Interface for Crawlee logger implementations.
|
|
10
|
+
* This allows users to inject custom loggers (e.g., Winston, Pino) while maintaining
|
|
11
|
+
* compatibility with the default `@apify/log` implementation.
|
|
12
|
+
*/
|
|
13
|
+
export interface CrawleeLogger {
|
|
14
|
+
/**
|
|
15
|
+
* Returns the logger configuration.
|
|
16
|
+
*/
|
|
17
|
+
getOptions(): CrawleeLoggerOptions;
|
|
18
|
+
/**
|
|
19
|
+
* Configures logger options.
|
|
20
|
+
*/
|
|
21
|
+
setOptions(options: Partial<CrawleeLoggerOptions>): void;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new instance of logger that inherits settings from a parent logger.
|
|
24
|
+
*/
|
|
25
|
+
child(options: Partial<CrawleeLoggerOptions>): CrawleeLogger;
|
|
26
|
+
/**
|
|
27
|
+
* Logs an `ERROR` message.
|
|
28
|
+
*/
|
|
29
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
30
|
+
/**
|
|
31
|
+
* Logs an `ERROR` level message with a nicely formatted exception.
|
|
32
|
+
*/
|
|
33
|
+
exception(exception: Error, message: string, data?: Record<string, unknown>): void;
|
|
34
|
+
/**
|
|
35
|
+
* Logs a `SOFT_FAIL` level message.
|
|
36
|
+
*/
|
|
37
|
+
softFail(message: string, data?: Record<string, unknown>): void;
|
|
38
|
+
/**
|
|
39
|
+
* Logs a `WARNING` level message.
|
|
40
|
+
*/
|
|
41
|
+
warning(message: string, data?: Record<string, unknown>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Logs a `WARNING` level message only once.
|
|
44
|
+
*/
|
|
45
|
+
warningOnce(message: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Logs an `INFO` message.
|
|
48
|
+
*/
|
|
49
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Logs a `DEBUG` message.
|
|
52
|
+
*/
|
|
53
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
54
|
+
/**
|
|
55
|
+
* Logs a `PERF` level message for performance tracking.
|
|
56
|
+
*/
|
|
57
|
+
perf(message: string, data?: Record<string, unknown>): void;
|
|
58
|
+
/**
|
|
59
|
+
* Logs given message only once as WARNING for deprecated features.
|
|
60
|
+
*/
|
|
61
|
+
deprecated(message: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Logs a message at the given level. Useful when the log level is determined dynamically.
|
|
64
|
+
*/
|
|
65
|
+
logWithLevel(level: number, message: string, data?: Record<string, unknown>): void;
|
|
66
|
+
}
|
package/logger.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/types",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.81",
|
|
4
4
|
"description": "Shared types for the crawlee projects",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.0.0"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://crawlee.dev",
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "
|
|
37
|
+
"build": "pnpm clean && pnpm compile && pnpm copy",
|
|
38
38
|
"clean": "rimraf ./dist",
|
|
39
39
|
"compile": "tsc -p tsconfig.build.json",
|
|
40
40
|
"copy": "tsx ../../scripts/copy.ts"
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
+
"tough-cookie": "^6.0.0",
|
|
46
47
|
"tslib": "^2.8.1"
|
|
47
48
|
},
|
|
48
49
|
"lerna": {
|
|
@@ -52,5 +53,5 @@
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
},
|
|
55
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "80dc6b4fc82237e63a51a71153809ec8dfd0cc50"
|
|
56
57
|
}
|
package/session.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { CookieJar, SerializedCookieJar } from 'tough-cookie';
|
|
2
|
+
/**
|
|
3
|
+
* The main purpose of the ProxyInfo object is to provide information
|
|
4
|
+
* about the current proxy connection used by the crawler for the request.
|
|
5
|
+
* Outside of crawlers, you can get this object by calling {@link ProxyConfiguration.newProxyInfo}.
|
|
6
|
+
*
|
|
7
|
+
* **Example usage:**
|
|
8
|
+
*
|
|
9
|
+
* ```javascript
|
|
10
|
+
* const proxyConfiguration = new ProxyConfiguration({
|
|
11
|
+
* proxyUrls: ['...', '...'] // List of Proxy URLs to rotate
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* // Getting proxyInfo object by calling class method directly
|
|
15
|
+
* const proxyInfo = await proxyConfiguration.newProxyInfo();
|
|
16
|
+
*
|
|
17
|
+
* // In crawler
|
|
18
|
+
* const crawler = new CheerioCrawler({
|
|
19
|
+
* // ...
|
|
20
|
+
* proxyConfiguration,
|
|
21
|
+
* requestHandler({ proxyInfo }) {
|
|
22
|
+
* // Getting used proxy URL
|
|
23
|
+
* const proxyUrl = proxyInfo.url;
|
|
24
|
+
* }
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export interface ProxyInfo {
|
|
30
|
+
/**
|
|
31
|
+
* The URL of the proxy.
|
|
32
|
+
*/
|
|
33
|
+
url: string;
|
|
34
|
+
/**
|
|
35
|
+
* Username for the proxy.
|
|
36
|
+
*/
|
|
37
|
+
username?: string;
|
|
38
|
+
/**
|
|
39
|
+
* User's password for the proxy.
|
|
40
|
+
*/
|
|
41
|
+
password: string;
|
|
42
|
+
/**
|
|
43
|
+
* Hostname of your proxy.
|
|
44
|
+
*/
|
|
45
|
+
hostname: string;
|
|
46
|
+
/**
|
|
47
|
+
* Proxy port.
|
|
48
|
+
*/
|
|
49
|
+
port: number | string;
|
|
50
|
+
/**
|
|
51
|
+
* When `true`, the proxy is likely intercepting HTTPS traffic and is able to view and modify its content.
|
|
52
|
+
*
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
ignoreTlsErrors?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Identifies the browser-like profile a {@link Session} is impersonating, so
|
|
59
|
+
* repeated requests with the same session look consistent to the target server.
|
|
60
|
+
*
|
|
61
|
+
* These fields are *hints* — `browser`, `platform`, `device`. Consumers
|
|
62
|
+
* (`@crawlee/browser-pool`, `@crawlee/impit-client`, …) derive their own rich
|
|
63
|
+
* state from them (e.g. a full browser fingerprint, a TLS impersonation profile)
|
|
64
|
+
* and cache it on their own; the session itself is read-only intent.
|
|
65
|
+
*/
|
|
66
|
+
export interface SessionFingerprint {
|
|
67
|
+
/** Browser family — consumed by HTTP clients that impersonate (e.g. `impit`). */
|
|
68
|
+
browser?: 'chrome' | 'firefox' | 'safari' | 'edge';
|
|
69
|
+
/** Platform hint — used by header generators and as a virtual session key. */
|
|
70
|
+
platform?: 'windows' | 'macos' | 'linux' | 'android' | 'ios';
|
|
71
|
+
/** Device class — drives header generation and viewport defaults. */
|
|
72
|
+
device?: 'desktop' | 'mobile';
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Persistable {@link Session} state.
|
|
76
|
+
*/
|
|
77
|
+
export interface SessionState {
|
|
78
|
+
id: string;
|
|
79
|
+
cookieJar: SerializedCookieJar;
|
|
80
|
+
proxyInfo?: ProxyInfo;
|
|
81
|
+
userData: object;
|
|
82
|
+
fingerprint?: SessionFingerprint;
|
|
83
|
+
errorScore: number;
|
|
84
|
+
maxErrorScore: number;
|
|
85
|
+
errorScoreDecrement: number;
|
|
86
|
+
usageCount: number;
|
|
87
|
+
maxUsageCount: number;
|
|
88
|
+
expiresAt: string;
|
|
89
|
+
createdAt: string;
|
|
90
|
+
retired: boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Sessions are used to store information such as cookies and can be used for generating fingerprints and proxy sessions.
|
|
94
|
+
* You can imagine each session as a specific user, with its own cookies, IP (via proxy) and potentially a unique browser fingerprint.
|
|
95
|
+
* Session internal state can be enriched with custom user data for example some authorization tokens and specific headers in general.
|
|
96
|
+
* @category Scaling
|
|
97
|
+
*/
|
|
98
|
+
export interface ISession {
|
|
99
|
+
readonly id: string;
|
|
100
|
+
cookieJar: CookieJar;
|
|
101
|
+
proxyInfo?: ProxyInfo;
|
|
102
|
+
fingerprint?: SessionFingerprint;
|
|
103
|
+
/**
|
|
104
|
+
* Indicates whether the session can be used for next requests.
|
|
105
|
+
* Session is usable when it is not expired, not blocked and the maximum usage count has not been reached.
|
|
106
|
+
*/
|
|
107
|
+
isUsable(): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* This method should be called after a successful session usage.
|
|
110
|
+
*/
|
|
111
|
+
markGood(): void;
|
|
112
|
+
/**
|
|
113
|
+
* Marks session as blocked.
|
|
114
|
+
* This method should be used if the session usage was unsuccessful
|
|
115
|
+
* and you are sure that it is because of the session configuration and not any external matters.
|
|
116
|
+
* For example when server returns 403 status code.
|
|
117
|
+
* If the session does not work due to some external factors as server error such as 5XX you probably want to use `markBad` method.
|
|
118
|
+
*/
|
|
119
|
+
retire(): void;
|
|
120
|
+
/**
|
|
121
|
+
* Increases usage and error count.
|
|
122
|
+
* Should be used when the session has been used unsuccessfully. For example because of timeouts.
|
|
123
|
+
*/
|
|
124
|
+
markBad(): void;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Minimal contract that any object passed to a crawler as its `sessionPool` option must satisfy.
|
|
128
|
+
*
|
|
129
|
+
* Crawlers only depend on a single method of the built-in `SessionPool`: `getSession()` /
|
|
130
|
+
* `getSession(id)` to hand out an {@link ISession} for a request. Lifecycle (reset, teardown)
|
|
131
|
+
* is the responsibility of whoever owns the pool — since a user-supplied pool is never owned by
|
|
132
|
+
* the crawler, the crawler never tears it down.
|
|
133
|
+
*
|
|
134
|
+
* Implement this interface to plug a custom session-management strategy into any Crawlee crawler —
|
|
135
|
+
* for example a remote, multi-process pool, a database-backed pool, or a thin wrapper around the
|
|
136
|
+
* built-in `SessionPool` with different rotation rules.
|
|
137
|
+
*
|
|
138
|
+
* @category Scaling
|
|
139
|
+
*/
|
|
140
|
+
export interface ISessionPool {
|
|
141
|
+
/**
|
|
142
|
+
* Returns a usable {@link ISession}. Without an id, the pool decides which session to return
|
|
143
|
+
* (creating a new one when appropriate). With an id, the pool returns the matching session if
|
|
144
|
+
* it is still usable.
|
|
145
|
+
*
|
|
146
|
+
* In case the `SessionPool` cannot provide a usable session given the configuration,
|
|
147
|
+
* this method may return `undefined`.
|
|
148
|
+
*/
|
|
149
|
+
getSession(sessionId?: string): Promise<ISession | undefined>;
|
|
150
|
+
}
|
package/session.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for setting a crawler run's status message via {@link BasicCrawler.setStatusMessage}.
|
|
3
|
+
*
|
|
4
|
+
* Setting a status message is not a storage concern — the crawler broadcasts it through the event
|
|
5
|
+
* system (`EventType.STATUS_MESSAGE`), and integrations such as the Apify SDK forward it to their
|
|
6
|
+
* status-reporting backend.
|
|
7
|
+
*/
|
|
8
|
+
export interface SetStatusMessageOptions {
|
|
9
|
+
/** Whether this is the final status message of the run. */
|
|
10
|
+
isStatusMessageTerminal?: boolean;
|
|
11
|
+
/** The log level to log the message with. Defaults to `'DEBUG'`. */
|
|
12
|
+
level?: 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|