@crawlee/impit-client 3.17.1-beta.20 → 3.17.1-beta.21

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.
Files changed (3) hide show
  1. package/index.d.ts +5 -0
  2. package/index.js +17 -3
  3. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare class ImpitHttpClient implements BaseHttpClient {
11
11
  private impitOptions;
12
12
  private maxRedirects;
13
13
  private followRedirects;
14
+ private cacheClients;
14
15
  /**
15
16
  * Enables reuse of `impit` clients for the same set of options.
16
17
  * This is useful for performance reasons, as creating
@@ -19,8 +20,12 @@ export declare class ImpitHttpClient implements BaseHttpClient {
19
20
  */
20
21
  private clientCache;
21
22
  private getClient;
23
+ /**
24
+ * @param options.cacheClients Whether to cache `impit` clients between requests. Defaults to `true`.
25
+ */
22
26
  constructor(options?: Omit<ImpitOptions, 'proxyUrl'> & {
23
27
  maxRedirects?: number;
28
+ cacheClients?: boolean;
24
29
  });
25
30
  /**
26
31
  * Flattens the headers of a `HttpRequest` to a format that can be passed to `impit`.
package/index.js CHANGED
@@ -14,6 +14,9 @@ exports.Browser = {
14
14
  */
15
15
  class ImpitHttpClient {
16
16
  getClient(options) {
17
+ if (!this.cacheClients) {
18
+ return new impit_1.Impit(options);
19
+ }
17
20
  const { cookieJar, ...rest } = options;
18
21
  const cacheKey = JSON.stringify(rest);
19
22
  const existingClient = this.clientCache.get(cacheKey);
@@ -24,6 +27,9 @@ class ImpitHttpClient {
24
27
  this.clientCache.add(cacheKey, { client, cookieJar: cookieJar });
25
28
  return client;
26
29
  }
30
+ /**
31
+ * @param options.cacheClients Whether to cache `impit` clients between requests. Defaults to `true`.
32
+ */
27
33
  constructor(options) {
28
34
  Object.defineProperty(this, "impitOptions", {
29
35
  enumerable: true,
@@ -43,6 +49,12 @@ class ImpitHttpClient {
43
49
  writable: true,
44
50
  value: void 0
45
51
  });
52
+ Object.defineProperty(this, "cacheClients", {
53
+ enumerable: true,
54
+ configurable: true,
55
+ writable: true,
56
+ value: void 0
57
+ });
46
58
  /**
47
59
  * Enables reuse of `impit` clients for the same set of options.
48
60
  * This is useful for performance reasons, as creating
@@ -55,9 +67,11 @@ class ImpitHttpClient {
55
67
  writable: true,
56
68
  value: new datastructures_1.LruCache({ maxLength: 10 })
57
69
  });
58
- this.impitOptions = options ?? {};
59
- this.maxRedirects = options?.maxRedirects ?? 10;
60
- this.followRedirects = options?.followRedirects ?? true;
70
+ const { maxRedirects = 10, followRedirects = true, cacheClients = true, ...impitOptions } = options ?? {};
71
+ this.impitOptions = impitOptions;
72
+ this.maxRedirects = maxRedirects;
73
+ this.followRedirects = followRedirects;
74
+ this.cacheClients = cacheClients;
61
75
  }
62
76
  /**
63
77
  * Flattens the headers of a `HttpRequest` to a format that can be passed to `impit`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/impit-client",
3
- "version": "3.17.1-beta.20",
3
+ "version": "3.17.1-beta.21",
4
4
  "description": "impit-based HTTP client implementation for Crawlee. Impersonates browser requests to avoid bot detection.",
5
5
  "engines": {
6
6
  "node": ">=20.0.0"
@@ -70,5 +70,5 @@
70
70
  }
71
71
  }
72
72
  },
73
- "gitHead": "0eefe28197a47cd2d969a068b7a9c0f1a065aa95"
73
+ "gitHead": "b315b66d9e3dffe8963cad291a85058ee0ef07c9"
74
74
  }