apify 4.0.0-beta.46 → 4.0.0-beta.48

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.
@@ -172,8 +172,12 @@ export declare class ProxyConfiguration extends CoreProxyConfiguration {
172
172
  * Returns a new {@link ProxyInfo} object with a fresh proxy URL. Each call mints an
173
173
  * independent URL; for Apify Proxy a random session id is embedded so consecutive
174
174
  * calls resolve to different IPs.
175
+ *
176
+ * A passed `proxyInfo` (e.g. one restored with a persisted session) is returned unchanged, unless it is an
177
+ * Apify Proxy one. Its endpoint is specific to the host, so it is moved to the current endpoint, keeping the
178
+ * username and with it the proxy session.
175
179
  */
176
- newProxyInfo(): Promise<ProxyInfo | undefined>;
180
+ newProxyInfo(proxyInfo?: ProxyInfo): Promise<ProxyInfo | undefined>;
177
181
  /**
178
182
  * Returns a new proxy URL. For Apify Proxy, each call generates a URL with a fresh
179
183
  * random session id, so consecutive calls return independent URLs. For custom
@@ -185,6 +189,7 @@ export declare class ProxyConfiguration extends CoreProxyConfiguration {
185
189
  */
186
190
  protected getUsername(sessionId: string): string;
187
191
  protected composeDefaultUrl(sessionId: string): string;
192
+ private composeUrl;
188
193
  /**
189
194
  * Fetch & set the proxy password from Apify API if an Apify token is provided.
190
195
  */
@@ -18,6 +18,7 @@ const SUBDIVISION_CODE_REGEX = /^[A-Z0-9]{1,3}$/;
18
18
  // users; a fresh one is minted for every URL the SDK hands out so that the
19
19
  // returned proxy URLs are independent.
20
20
  const SESSION_ID_LENGTH = 12;
21
+ const SESSION_USERNAME_REGEX = /(?:^|,)session-[^,]+/;
21
22
  /**
22
23
  * Configures connection to a proxy server with the provided options. Proxy servers are used to prevent target websites from blocking
23
24
  * your crawlers based on IP address rate limits or blacklists. Setting proxy configuration in your crawlers automatically configures
@@ -146,9 +147,18 @@ export class ProxyConfiguration extends CoreProxyConfiguration {
146
147
  * Returns a new {@link ProxyInfo} object with a fresh proxy URL. Each call mints an
147
148
  * independent URL; for Apify Proxy a random session id is embedded so consecutive
148
149
  * calls resolve to different IPs.
150
+ *
151
+ * A passed `proxyInfo` (e.g. one restored with a persisted session) is returned unchanged, unless it is an
152
+ * Apify Proxy one. Its endpoint is specific to the host, so it is moved to the current endpoint, keeping the
153
+ * username and with it the proxy session.
149
154
  */
150
- async newProxyInfo() {
151
- const url = await this.newUrl();
155
+ async newProxyInfo(proxyInfo) {
156
+ // Only Apify Proxy infos carry `groups` and a proxy session in the username.
157
+ if (proxyInfo &&
158
+ !(this.#usesApifyProxy && 'groups' in proxyInfo && SESSION_USERNAME_REGEX.test(proxyInfo.username ?? ''))) {
159
+ return proxyInfo;
160
+ }
161
+ const url = proxyInfo?.username ? this.composeUrl(proxyInfo.username) : await this.newUrl();
152
162
  if (!url)
153
163
  return undefined;
154
164
  const parsed = new URL(url);
@@ -159,6 +169,9 @@ export class ProxyConfiguration extends CoreProxyConfiguration {
159
169
  hostname: parsed.hostname,
160
170
  port: parsed.port,
161
171
  };
172
+ // A refreshed info keeps its own groups/country, which match its username rather than this config.
173
+ if (proxyInfo)
174
+ return { ...proxyInfo, ...result };
162
175
  if (this.#usesApifyProxy) {
163
176
  result.groups = this.#groups;
164
177
  if (this.#countryCode !== undefined)
@@ -197,7 +210,9 @@ export class ProxyConfiguration extends CoreProxyConfiguration {
197
210
  return parts.join(',');
198
211
  }
199
212
  composeDefaultUrl(sessionId) {
200
- const username = this.getUsername(sessionId);
213
+ return this.composeUrl(this.getUsername(sessionId));
214
+ }
215
+ composeUrl(username) {
201
216
  const url = new URL(`http://${this.#hostname}:${this.#port}`);
202
217
  url.username = `${username}`;
203
218
  url.password = `${this.#password}`;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "apify",
3
- "version": "4.0.0-beta.46",
3
+ "version": "4.0.0-beta.48",
4
4
  "description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
5
5
  "engines": {
6
- "node": ">=22.0.0"
6
+ "node": ">=22.13.0"
7
7
  },
8
8
  "type": "module",
9
9
  "main": "./dist/index.js",
@@ -61,10 +61,10 @@
61
61
  "@apify/timeout": "^1.0.1",
62
62
  "@apify/utilities": "^3.1.0",
63
63
  "@apify/validations": "^1.1.1",
64
- "@crawlee/core": "4.0.0-beta.201",
65
- "@crawlee/fs-storage": "4.0.0-beta.201",
66
- "@crawlee/types": "4.0.0-beta.201",
67
- "@crawlee/utils": "4.0.0-beta.201",
64
+ "@crawlee/core": "4.0.0-beta.213",
65
+ "@crawlee/fs-storage": "4.0.0-beta.213",
66
+ "@crawlee/types": "4.0.0-beta.213",
67
+ "@crawlee/utils": "4.0.0-beta.213",
68
68
  "apify-client": "^3.0.0-beta.28",
69
69
  "minimatch": "^10.2.6",
70
70
  "semver": "^7.8.5",
@@ -81,7 +81,7 @@
81
81
  "@types/semver": "^7.8.0",
82
82
  "@types/ws": "^8.18.1",
83
83
  "commitlint": "^21.2.3",
84
- "crawlee": "4.0.0-beta.201",
84
+ "crawlee": "4.0.0-beta.213",
85
85
  "husky": "^9.1.7",
86
86
  "lint-staged": "^17.6.0",
87
87
  "oxfmt": "0.71.0",