@crawlee/types 4.0.0-beta.99 → 4.0.0-rc.1
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 +1 -1
- package/browser.d.ts +6 -11
- package/cookies.d.ts +82 -0
- package/cookies.js +1 -0
- package/http-client.d.ts +7 -20
- package/index.d.ts +1 -0
- package/logger.d.ts +14 -7
- package/package.json +3 -4
- package/session.d.ts +9 -1
- package/storages.d.ts +25 -3
- package/utility-types.d.ts +0 -2
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) N
|
|
|
34
34
|
|
|
35
35
|
We recommend visiting the [Introduction tutorial](https://crawlee.dev/js/docs/introduction) in Crawlee documentation for more information.
|
|
36
36
|
|
|
37
|
-
> Crawlee requires **Node.js
|
|
37
|
+
> Crawlee requires **Node.js 22.13 or higher**.
|
|
38
38
|
|
|
39
39
|
### With Crawlee CLI
|
|
40
40
|
|
package/browser.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ISession } from './session.js';
|
|
2
|
-
import type { Dictionary } from './utility-types.js';
|
|
3
2
|
export interface Cookie {
|
|
4
3
|
/**
|
|
5
4
|
* Cookie name.
|
|
@@ -57,10 +56,6 @@ export interface Cookie {
|
|
|
57
56
|
*/
|
|
58
57
|
sourcePort?: number;
|
|
59
58
|
}
|
|
60
|
-
export interface BrowserLikeResponse {
|
|
61
|
-
url(): string;
|
|
62
|
-
headers(): Dictionary<string | string[]>;
|
|
63
|
-
}
|
|
64
59
|
/**
|
|
65
60
|
* A snapshot of the relevant state of a page, as extracted by
|
|
66
61
|
* {@link IBrowserPool.extractPageState}.
|
|
@@ -125,14 +120,14 @@ export interface IBrowserPool<Page = unknown> {
|
|
|
125
120
|
/**
|
|
126
121
|
* Signals the pool that the caller is done with the page. The pool is
|
|
127
122
|
* responsible for closing the page and performing any necessary cleanup
|
|
128
|
-
* (e.g. retiring the underlying browser
|
|
123
|
+
* (e.g. retiring the underlying browser once the page's session is finished).
|
|
129
124
|
*
|
|
130
125
|
* @param page The page to release back to the pool.
|
|
131
|
-
* @param options.error If the
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
126
|
+
* @param options.error If the error is a {@link SessionError}, the
|
|
127
|
+
* session that served the page is finished. A plain `SessionError`
|
|
128
|
+
* means it was blocked: discard any browser state tied to it. A
|
|
129
|
+
* {@link SessionRetiredError} means it merely reached its usage or
|
|
130
|
+
* age limit, so a pool may keep a warm page instead.
|
|
136
131
|
*/
|
|
137
132
|
closePage(page: Page, options?: {
|
|
138
133
|
error?: Error;
|
package/cookies.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cookie shape used by {@link CookieJar}. Structurally compatible with `tough-cookie`'s
|
|
3
|
+
* `Cookie` class, so a `tough-cookie` cookie satisfies it without `@crawlee/types` depending
|
|
4
|
+
* on `tough-cookie` itself.
|
|
5
|
+
*/
|
|
6
|
+
export interface SessionCookie {
|
|
7
|
+
key: string;
|
|
8
|
+
value: string;
|
|
9
|
+
expires: Date | 'Infinity' | null;
|
|
10
|
+
maxAge: number | 'Infinity' | '-Infinity' | null;
|
|
11
|
+
domain: string | null;
|
|
12
|
+
path: string | null;
|
|
13
|
+
secure: boolean;
|
|
14
|
+
httpOnly: boolean;
|
|
15
|
+
extensions: string[] | null;
|
|
16
|
+
creation: Date | 'Infinity' | null;
|
|
17
|
+
creationIndex: number;
|
|
18
|
+
hostOnly: boolean | null;
|
|
19
|
+
pathIsDefault: boolean | null;
|
|
20
|
+
lastAccessed: Date | 'Infinity' | null;
|
|
21
|
+
sameSite: string | undefined;
|
|
22
|
+
toJSON(): Record<string, unknown>;
|
|
23
|
+
clone(): SessionCookie | undefined;
|
|
24
|
+
validate(): boolean;
|
|
25
|
+
setExpires(exp: string | Date): void;
|
|
26
|
+
setMaxAge(age: number): void;
|
|
27
|
+
cookieString(): string;
|
|
28
|
+
toString(): string;
|
|
29
|
+
TTL(now?: number): number;
|
|
30
|
+
expiryTime(now?: Date): number | undefined;
|
|
31
|
+
expiryDate(now?: Date): Date | undefined;
|
|
32
|
+
isPersistent(): boolean;
|
|
33
|
+
canonicalizedDomain(): string | undefined;
|
|
34
|
+
cdomain(): string | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Options for {@link CookieJar.setCookie}. Structurally compatible with `tough-cookie`'s
|
|
38
|
+
* `SetCookieOptions`.
|
|
39
|
+
*/
|
|
40
|
+
export interface CookieJarSetCookieOptions {
|
|
41
|
+
loose?: boolean;
|
|
42
|
+
sameSiteContext?: 'strict' | 'lax' | 'none';
|
|
43
|
+
ignoreError?: boolean;
|
|
44
|
+
http?: boolean;
|
|
45
|
+
now?: Date;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Options for {@link CookieJar}'s cookie-reading methods. Structurally compatible with
|
|
49
|
+
* `tough-cookie`'s `GetCookiesOptions`.
|
|
50
|
+
*/
|
|
51
|
+
export interface CookieJarGetCookiesOptions {
|
|
52
|
+
http?: boolean;
|
|
53
|
+
expire?: boolean;
|
|
54
|
+
allPaths?: boolean;
|
|
55
|
+
sameSiteContext?: 'none' | 'lax' | 'strict';
|
|
56
|
+
sort?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Cookie jar contract, structurally compatible with `tough-cookie`'s `CookieJar` — which is
|
|
60
|
+
* what backs {@link Session} by default — so `@crawlee/types` does not have to depend on
|
|
61
|
+
* `tough-cookie` for it.
|
|
62
|
+
*/
|
|
63
|
+
export interface CookieJar {
|
|
64
|
+
setCookie(cookie: string | SessionCookie, url: string | URL, options?: CookieJarSetCookieOptions): Promise<SessionCookie | undefined>;
|
|
65
|
+
getCookies(url: string | URL, options?: CookieJarGetCookiesOptions): Promise<SessionCookie[]>;
|
|
66
|
+
getCookieString(url: string | URL, options?: CookieJarGetCookiesOptions): Promise<string>;
|
|
67
|
+
getSetCookieStrings(url: string | URL, options?: CookieJarGetCookiesOptions): Promise<string[] | undefined>;
|
|
68
|
+
serialize(): Promise<SerializedCookieJar>;
|
|
69
|
+
toJSON(): SerializedCookieJar | undefined;
|
|
70
|
+
clone(): Promise<CookieJar>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* JSON representation of a {@link CookieJar}. Structurally compatible with `tough-cookie`'s
|
|
74
|
+
* `SerializedCookieJar`.
|
|
75
|
+
*/
|
|
76
|
+
export interface SerializedCookieJar {
|
|
77
|
+
version: string;
|
|
78
|
+
storeType: string | null;
|
|
79
|
+
rejectPublicSuffixes: boolean;
|
|
80
|
+
cookies: Record<string, unknown>[];
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
}
|
package/cookies.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/http-client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream';
|
|
2
|
-
import type { CookieJar } from '
|
|
2
|
+
import type { CookieJar } from './cookies.js';
|
|
3
3
|
import type { ISession } from './session.js';
|
|
4
4
|
import type { AllowedHttpMethods } from './utility-types.js';
|
|
5
5
|
export type SearchParams = string | URLSearchParams | Record<string, string | number | boolean | null | undefined>;
|
|
@@ -15,17 +15,8 @@ export interface HttpRequest {
|
|
|
15
15
|
timeout?: number;
|
|
16
16
|
cookieJar?: CookieJar;
|
|
17
17
|
followRedirect?: boolean | ((response: any) => boolean);
|
|
18
|
-
maxRedirects?: number;
|
|
19
18
|
encoding?: BufferEncoding;
|
|
20
|
-
throwHttpErrors?: boolean;
|
|
21
19
|
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
20
|
}
|
|
30
21
|
/**
|
|
31
22
|
* Additional options for HTTP requests that need to be handled separately before passing to {@link BaseHttpClient}.
|
|
@@ -42,13 +33,6 @@ export interface HttpRequestOptions extends HttpRequest {
|
|
|
42
33
|
/** Basic HTTP Auth password */
|
|
43
34
|
password?: string;
|
|
44
35
|
}
|
|
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
36
|
export interface SendRequestOptions {
|
|
53
37
|
session?: ISession;
|
|
54
38
|
cookieJar?: CookieJar;
|
|
@@ -62,9 +46,12 @@ export interface SendRequestOptions {
|
|
|
62
46
|
* Note that setting this manually can interfere with session proxy rotation.
|
|
63
47
|
*/
|
|
64
48
|
proxyUrl?: string;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
/**
|
|
50
|
+
* When `true`, TLS certificate errors are ignored for this request. Also enabled by
|
|
51
|
+
* `session.proxyInfo.ignoreTlsErrors` (MITM proxies). Best-effort: clients that cannot
|
|
52
|
+
* disable TLS verification (e.g. the native fetch fallback) ignore it.
|
|
53
|
+
*/
|
|
54
|
+
ignoreTlsErrors?: boolean;
|
|
68
55
|
}
|
|
69
56
|
/**
|
|
70
57
|
* Interface for user-defined HTTP clients to be used for plain HTTP crawling and for sending additional requests during a crawl.
|
package/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export type * from './status-message.js';
|
|
|
2
2
|
export type * from './storages.js';
|
|
3
3
|
export type * from './utility-types.js';
|
|
4
4
|
export type * from './browser.js';
|
|
5
|
+
export type * from './cookies.js';
|
|
5
6
|
export type * from './http-client.js';
|
|
6
7
|
export type * from './session.js';
|
|
7
8
|
export type * from './logger.js';
|
package/logger.d.ts
CHANGED
|
@@ -5,6 +5,13 @@ export interface CrawleeLoggerOptions {
|
|
|
5
5
|
/** Prefix to be prepended to each logged line. */
|
|
6
6
|
prefix?: string | null;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Options for a single log call.
|
|
10
|
+
*/
|
|
11
|
+
export interface LogOptions {
|
|
12
|
+
/** Log the message only the first time this logger sees that text, ignoring later calls with it. */
|
|
13
|
+
once?: boolean;
|
|
14
|
+
}
|
|
8
15
|
/**
|
|
9
16
|
* Interface for Crawlee logger implementations.
|
|
10
17
|
* This allows users to inject custom loggers (e.g., Winston, Pino) while maintaining
|
|
@@ -26,7 +33,7 @@ export interface CrawleeLogger {
|
|
|
26
33
|
/**
|
|
27
34
|
* Logs an `ERROR` message.
|
|
28
35
|
*/
|
|
29
|
-
error(message: string, data?: Record<string, unknown
|
|
36
|
+
error(message: string, data?: Record<string, unknown>, options?: LogOptions): void;
|
|
30
37
|
/**
|
|
31
38
|
* Logs an `ERROR` level message with a nicely formatted exception.
|
|
32
39
|
*/
|
|
@@ -34,27 +41,27 @@ export interface CrawleeLogger {
|
|
|
34
41
|
/**
|
|
35
42
|
* Logs a `SOFT_FAIL` level message.
|
|
36
43
|
*/
|
|
37
|
-
softFail(message: string, data?: Record<string, unknown
|
|
44
|
+
softFail(message: string, data?: Record<string, unknown>, options?: LogOptions): void;
|
|
38
45
|
/**
|
|
39
46
|
* Logs a `WARNING` level message.
|
|
40
47
|
*/
|
|
41
|
-
warning(message: string, data?: Record<string, unknown
|
|
48
|
+
warning(message: string, data?: Record<string, unknown>, options?: LogOptions): void;
|
|
42
49
|
/**
|
|
43
|
-
* Logs a `WARNING` level message only once.
|
|
50
|
+
* Logs a `WARNING` level message only once. Shorthand for `warning(message, undefined, { once: true })`.
|
|
44
51
|
*/
|
|
45
52
|
warningOnce(message: string): void;
|
|
46
53
|
/**
|
|
47
54
|
* Logs an `INFO` message.
|
|
48
55
|
*/
|
|
49
|
-
info(message: string, data?: Record<string, unknown
|
|
56
|
+
info(message: string, data?: Record<string, unknown>, options?: LogOptions): void;
|
|
50
57
|
/**
|
|
51
58
|
* Logs a `DEBUG` message.
|
|
52
59
|
*/
|
|
53
|
-
debug(message: string, data?: Record<string, unknown
|
|
60
|
+
debug(message: string, data?: Record<string, unknown>, options?: LogOptions): void;
|
|
54
61
|
/**
|
|
55
62
|
* Logs a `PERF` level message for performance tracking.
|
|
56
63
|
*/
|
|
57
|
-
perf(message: string, data?: Record<string, unknown
|
|
64
|
+
perf(message: string, data?: Record<string, unknown>, options?: LogOptions): void;
|
|
58
65
|
/**
|
|
59
66
|
* Logs given message only once as WARNING for deprecated features.
|
|
60
67
|
*/
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/types",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-rc.1",
|
|
4
4
|
"description": "Shared types for the crawlee projects",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=22.
|
|
6
|
+
"node": ">=22.13.0"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"tough-cookie": "^6.0.0",
|
|
47
46
|
"tslib": "^2.8.1"
|
|
48
47
|
},
|
|
49
48
|
"lerna": {
|
|
@@ -53,5 +52,5 @@
|
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
},
|
|
56
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "f354ca5e943bed1a5c657a1fce1974c053f9fff0"
|
|
57
56
|
}
|
package/session.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CookieJar, SerializedCookieJar } from '
|
|
1
|
+
import type { CookieJar, SerializedCookieJar } from './cookies.js';
|
|
2
2
|
/**
|
|
3
3
|
* The main purpose of the ProxyInfo object is to provide information
|
|
4
4
|
* about the current proxy connection used by the crawler for the request.
|
|
@@ -49,6 +49,8 @@ export interface ProxyInfo {
|
|
|
49
49
|
port: number | string;
|
|
50
50
|
/**
|
|
51
51
|
* When `true`, the proxy is likely intercepting HTTPS traffic and is able to view and modify its content.
|
|
52
|
+
* The built-in HTTP clients and the browser pool disable TLS certificate verification for the session's
|
|
53
|
+
* requests when this is set.
|
|
52
54
|
*
|
|
53
55
|
* @default false
|
|
54
56
|
*/
|
|
@@ -73,6 +75,7 @@ export interface SessionFingerprint {
|
|
|
73
75
|
}
|
|
74
76
|
/**
|
|
75
77
|
* Persistable {@link Session} state.
|
|
78
|
+
* @internal
|
|
76
79
|
*/
|
|
77
80
|
export interface SessionState {
|
|
78
81
|
id: string;
|
|
@@ -105,6 +108,11 @@ export interface ISession {
|
|
|
105
108
|
* Session is usable when it is not expired, not blocked and the maximum usage count has not been reached.
|
|
106
109
|
*/
|
|
107
110
|
isUsable(): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Indicates whether the session is blocked, i.e. its error score reached the maximum or it was retired via `retire()`.
|
|
113
|
+
* Unlike other reasons for not being usable, this means the identity itself is burned.
|
|
114
|
+
*/
|
|
115
|
+
isBlocked(): boolean;
|
|
108
116
|
/**
|
|
109
117
|
* This method should be called after a successful session usage.
|
|
110
118
|
*/
|
package/storages.d.ts
CHANGED
|
@@ -174,7 +174,14 @@ export interface KeyValueStoreBackend {
|
|
|
174
174
|
* instead of inferring the end from `items.length < limit`.
|
|
175
175
|
*/
|
|
176
176
|
listKeys(options?: KeyValueStoreListKeysOptions): Promise<KeyValueStoreListKeysResult>;
|
|
177
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* Get the public URL a record with this key has, or `undefined` if the backend exposes no public
|
|
179
|
+
* URLs at all.
|
|
180
|
+
*
|
|
181
|
+
* The URL is derived from the key; implementations MUST NOT check that the record exists. Callers
|
|
182
|
+
* legitimately ask for the URL of a record that is not on the backend yet — most notably one
|
|
183
|
+
* buffered in an uncommitted storage transaction — and existence is `recordExists`'s job.
|
|
184
|
+
*/
|
|
178
185
|
getPublicUrl(key: string): Promise<string | undefined>;
|
|
179
186
|
/** Check whether a record with the given key exists. */
|
|
180
187
|
recordExists(key: string): Promise<boolean>;
|
|
@@ -329,15 +336,26 @@ export interface RequestQueueBackend {
|
|
|
329
336
|
* still being processed. Clients that do not lock may ignore it.
|
|
330
337
|
*/
|
|
331
338
|
setExpectedRequestProcessingTimeSecs?(secs: number): Promise<void>;
|
|
339
|
+
/**
|
|
340
|
+
* Extends the lock on a request previously handed out by {@link fetchNextRequest}, for a consumer
|
|
341
|
+
* that needs more time than the sizing hint reserved.
|
|
342
|
+
*
|
|
343
|
+
* @returns `true` when prolonged, `false` when this client does not hold the request locked (or
|
|
344
|
+
* does not lock at all). `false` is information, not an error: the request may be processed twice.
|
|
345
|
+
* Non-locking backends leave this unimplemented.
|
|
346
|
+
*/
|
|
347
|
+
extendRequestProcessingTimeSecs?(requestId: string, secs: number): Promise<boolean>;
|
|
332
348
|
}
|
|
333
349
|
/**
|
|
334
350
|
* Identifies a storage by its ID, name, or alias. At most one may be provided.
|
|
335
351
|
*
|
|
336
352
|
* - `{ id }` — open a pre-existing storage by its unique ID.
|
|
337
|
-
* - `{ name }` — open or create a globally named storage (persists across runs).
|
|
353
|
+
* - `{ name }` — open or create a globally named storage (persists across runs). The name `default`
|
|
354
|
+
* is reserved: it resolves to the default storage, and is emptied on start along with it.
|
|
338
355
|
* - `{ alias }` — open or create a run-scoped unnamed storage identified by this alias.
|
|
339
356
|
* The alias is used locally (e.g. as a directory name or cache key) but the storage
|
|
340
|
-
* itself has no persistent name. Use this for non-default unnamed storages.
|
|
357
|
+
* itself has no persistent name. Use this for non-default unnamed storages. Like the
|
|
358
|
+
* default storage, an aliased one is emptied on start unless `purgeOnStart` is disabled.
|
|
341
359
|
* - `{}` / omitted — open the default storage.
|
|
342
360
|
*/
|
|
343
361
|
export type StorageIdentifier = {
|
|
@@ -409,6 +427,10 @@ export interface StorageBackend {
|
|
|
409
427
|
* `StorageBackend` implementations automatically get separate cache partitions.
|
|
410
428
|
*/
|
|
411
429
|
getStorageBackendCacheKey?(): string;
|
|
430
|
+
/**
|
|
431
|
+
* Empty the run-scoped storages — the default one and every alias-keyed one, including any left
|
|
432
|
+
* behind by a previous run. Named storages persist across runs.
|
|
433
|
+
*/
|
|
412
434
|
purge?(): Promise<void>;
|
|
413
435
|
teardown?(): Promise<void>;
|
|
414
436
|
stats?: {
|
package/utility-types.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export type Dictionary<T = any> = Record<PropertyKey, T>;
|
|
2
|
-
/** @ignore */
|
|
3
2
|
export type Constructor<T = unknown> = new (...args: any[]) => T;
|
|
4
|
-
/** @ignore */
|
|
5
3
|
export type Awaitable<T> = T | PromiseLike<T>;
|
|
6
4
|
export type AllowedHttpMethods = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'OPTIONS' | 'CONNECT' | 'PATCH' | 'get' | 'head' | 'post' | 'put' | 'delete' | 'trace' | 'options' | 'connect' | 'patch';
|