Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions docs/04_upgrading/upgrading_v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Before (v3):
```ts
import { Configuration } from 'apify';

const config = Configuration.getGlobalConfig();
const config = Configuration.getGlobalConfiguration();
const token = config.get('token');
config.set('token', 'new-token');
```
Expand All @@ -51,6 +51,8 @@ When a setting is exposed under several environment variables, the Apify-specifi

`new Actor({ configuration })` accepts a pre-built `Configuration`, but it must be the Apify SDK's `Configuration` (imported from `apify`), not a bare Crawlee one — otherwise the `APIFY_*` / `ACTOR_*` environment variables are never resolved, so the SDK now throws if given a non-Apify instance.

`Actor.config` was renamed to `Actor.configuration` (both the static getter and the instance property), and `Configuration.getGlobalConfig()` to `Configuration.getGlobalConfiguration()`, following the same renames in Crawlee v4. The public `config` properties of `ProxyConfiguration` and `PlatformEventManager` were renamed to `configuration` as well.

## ProxyConfiguration: `newUrl()` / `newProxyInfo()` no longer take `sessionId`

The `sessionId` parameter has been removed from both `ProxyConfiguration.newUrl()` and `ProxyConfiguration.newProxyInfo()`. Each call now returns an independent URL; for Apify Proxy the SDK mints a fresh random session id internally for every URL it hands out, so consecutive calls resolve to different IPs.
Expand Down Expand Up @@ -87,15 +89,15 @@ The `tieredProxyUrls` and `tieredProxyConfig` options on `ProxyConfigurationOpti

## EventManager

`PlatformEventManager` now extends Crawlee v4's `EventManager` and integrates with the new service locator. Use `Configuration.getGlobalConfig()` (or pass a `Configuration` instance explicitly) when constructing it directly — the constructor no longer accepts a `config` override via the `override` keyword pattern because Crawlee's base class manages the configuration through `serviceLocator` instead of a `config` field.
`PlatformEventManager` now extends Crawlee v4's `EventManager` and integrates with the new service locator. Use `Configuration.getGlobalConfiguration()` (or pass a `Configuration` instance explicitly) when constructing it directly — the constructor no longer accepts a `config` override via the `override` keyword pattern because Crawlee's base class manages the configuration through `serviceLocator` instead of a `config` field.

If you only interact with events through `Actor.on()` / `Actor.off()` / `Actor.events`, no code changes are needed.

## StorageClient
## StorageBackend

The SDK's storage layer was adapted to the new Crawlee v4 `StorageClient` interface. The Apify platform client is wrapped via the `ApifyStorageClient` adapter — now exported from `apify` — which implements `createDatasetClient`, `createKeyValueStoreClient`, and `createRequestQueueClient`.
The SDK's storage layer was adapted to the new Crawlee v4 `StorageBackend` interface. The Apify platform client is wrapped via the `ApifyStorageBackend` adapter — now exported from `apify` — which implements `createDatasetBackend`, `createKeyValueStoreBackend`, and `createRequestQueueBackend`.

`Actor` wires this up for you, so most code needs no changes. But if you previously passed a raw `apify-client` `ApifyClient` straight into a Crawlee storage as its `storageClient` — which worked in v3 — it no longer does: Crawlee v4 calls `createKeyValueStoreClient()` / `createDatasetClient()`, which the raw client doesn't implement. Wrap it in `ApifyStorageClient`:
`Actor` wires this up for you, so most code needs no changes. But if you previously passed a raw `apify-client` `ApifyClient` straight into a Crawlee storage as its `storageClient` — which worked in v3 — it no longer does: Crawlee v4 calls `createKeyValueStoreBackend()` / `createDatasetBackend()`, which the raw client doesn't implement. Wrap it in `ApifyStorageBackend`:

```ts
// v3
Expand All @@ -105,10 +107,21 @@ const client = new ApifyClient({ token });
const store = await KeyValueStore.open(storeId, { storageClient: client });

// v4
import { ApifyClient, ApifyStorageClient, KeyValueStore } from 'apify';
import { ApifyClient, ApifyStorageBackend, KeyValueStore } from 'apify';

const client = new ApifyClient({ token });
const store = await KeyValueStore.open(storeId, { storageClient: new ApifyStorageClient(client) });
const store = await KeyValueStore.open(storeId, { storageBackend: new ApifyStorageBackend(client) });
```

### Request queue access modes

On the platform, request queues can now be consumed in two modes, controlled by the `requestQueueAccess` option of `Actor.init()` (or of `ApifyStorageBackend` when constructing it directly):

- `'single'` (default) assumes the run is the only consumer of its request queues. Requests are not locked server-side and the queue head is estimated locally, which means fewer (paid) API calls and better performance. Multiple producers may still add requests concurrently.
- `'shared'` locks every fetched request server-side, so several concurrent consumers (e.g. multiple Actor runs) can process one queue safely, at the cost of roughly one extra API call per request.

```ts
await Actor.init({ requestQueueAccess: 'shared' });
```

`KeyValueStore.getPublicUrl()` is now asynchronous (it signs URLs server-side when running on the Apify platform). Update call sites accordingly:
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@
},
"dependencies": {
"@apify/consts": "^2.51.0",
"@apify/datastructures": "^2.0.3",
"@apify/input_secrets": "^1.2.0",
"@apify/log": "^2.4.3",
"@apify/timeout": "^0.3.0",
"@apify/utilities": "^2.13.0",
"@crawlee/core": "^4.0.0-beta.61",
"@crawlee/types": "^4.0.0-beta.61",
"@crawlee/utils": "^4.0.0-beta.61",
"@crawlee/core": "^4.0.0-beta.105",
"@crawlee/types": "^4.0.0-beta.105",
"@crawlee/utils": "^4.0.0-beta.105",
"apify-client": "^2.23.4",
"semver": "^7.5.4",
"tslib": "^2.6.2",
Expand All @@ -90,15 +91,14 @@
"@apify/oxlint-config": "^0.2.5",
"@apify/tsconfig": "^0.1.2",
"@commitlint/config-conventional": "^21.0.0",
"@crawlee/memory-storage": "^4.0.0-beta.61",
"@playwright/browser-chromium": "^1.60.0",
"@types/content-type": "^1.1.8",
"@types/node": "^24.0.0",
"@types/semver": "^7.5.8",
"@types/tough-cookie": "^4.0.5",
"@types/ws": "^8.5.12",
"commitlint": "^21.0.0",
"crawlee": "^4.0.0-beta.61",
"crawlee": "^4.0.0-beta.105",
"globby": "^16.0.0",
"husky": "^9.1.7",
"lint-staged": "^17.0.0",
Expand Down
Loading
Loading