From 23e1ae217be4ee358fd053fc990f895f0011854b Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 16:22:12 +0000 Subject: [PATCH 1/5] chore: sync PHP client with Apify OpenAPI spec v2-2026-11-10T140017Z Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_017ocuAJ6an2FrPuYqCvUoaA --- CHANGELOG.md | 6 ++++++ README.md | 3 ++- docs/runs.md | 2 +- src/Resource/RunClient.php | 5 ++++- src/Version.php | 4 ++-- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e277cd..859c5d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.14.1 + +- Synced with Apify OpenAPI spec `v2-2026-11-10T140017Z`, which only changes descriptions. +- Documented that `RunClient::charge()` is called from the Actor run with the `APIFY_TOKEN` of the run, and how to charge a multi-tenant Server Actor request. +- Documented that the Console shows an API token only once. + ## 0.14.0 - Synced with Apify OpenAPI spec `v2-2026-11-09T143926Z`: `zstd` is a documented `Content-Encoding`. diff --git a/README.md b/README.md index 31bbaad..0d726eb 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,8 @@ echo 'Item count: ' . $items->getCount() . PHP_EOL; ``` The client does not read `APIFY_TOKEN`. Pass it yourself, for example `new ApifyClient(getenv('APIFY_TOKEN'))`. -You can find your token in [Apify Console → Settings → API & Integrations](https://console.apify.com/settings/integrations). +You can create a token in [Apify Console → Settings → API & Integrations](https://console.apify.com/settings/integrations). +The Console shows a token only once, right after you create or rotate it, so store it somewhere safe. ## Configuration diff --git a/docs/runs.md b/docs/runs.md index 8f02e91..8da22c0 100644 --- a/docs/runs.md +++ b/docs/runs.md @@ -26,7 +26,7 @@ An Actor's or task's runs are available at `$client->actor($id)->runs()` / `$cli - `metamorph(string $targetActorId, mixed $input = null, ?MetamorphOptions $options = null): ActorRun`: `$input` is as for `ActorClient::start()`. - `reboot(): ActorRun` - `resurrect(?RunResurrectOptions $options = null): ActorRun` -- `charge(RunChargeOptions $options): void`: for pay-per-event Actors. +- `charge(RunChargeOptions $options): void`: for pay-per-event Actors. Call it from the Actor run itself, with the token the run received in `APIFY_TOKEN`. For a multi-tenant Server Actor, set `requestId` to the request's `X-Actor-Request-ID` header value. - `waitForFinish(?int $waitSecs = null, int|float|string|null $timeoutSecs = null): ActorRun`: `$timeoutSecs` is the timeout of each poll request (default `'noTimeout'`). - `dataset(): DatasetClient`, `keyValueStore(): KeyValueStoreClient`, `requestQueue(): RequestQueueClient`: a 404 from `get()` or `delete()` is thrown, since the client cannot tell a missing run from a missing storage. - `iterateDatasetItems(?RunIterateDatasetItemsOptions $options = null, int|float|string|null $timeoutSecs = null): Generator`: lazily yields the items of the default dataset while the run is producing them, and returns when the run has finished and the dataset is drained. `$timeoutSecs` is the timeout of each request, polls included (default: the `long` tier). See [below](#reading-a-dataset-while-the-run-is-running). diff --git a/src/Resource/RunClient.php b/src/Resource/RunClient.php index 1e05404..098d5bf 100644 --- a/src/Resource/RunClient.php +++ b/src/Resource/RunClient.php @@ -156,7 +156,10 @@ public function resurrect(?RunResurrectOptions $options = null, int|float|string /** * Charges for events of a pay-per-event Actor run. * - * The request always carries an idempotency key, so a retried charge is applied once. + * Call it from the Actor run itself, with a client that uses the token the run received in its + * {@code APIFY_TOKEN} environment variable. The request always carries an idempotency key, so a retried + * charge is applied once. To charge a request to a multi-tenant Server Actor, set + * {@see RunChargeOptions::$requestId} to the request's {@code X-Actor-Request-ID} header value. */ public function charge(RunChargeOptions $options, int|float|string|null $timeoutSecs = null): void { diff --git a/src/Version.php b/src/Version.php index cbb9841..5644b6d 100644 --- a/src/Version.php +++ b/src/Version.php @@ -17,13 +17,13 @@ final class Version * The semantic version of this client library (see https://semver.org/). * Changes to the public interface other than additive ones are considered breaking changes. */ - public const CLIENT_VERSION = '0.14.0'; + public const CLIENT_VERSION = '0.14.1'; /** * The version of the Apify OpenAPI specification this client was generated and verified * against. Corresponds to the {@code info.version} field of the Apify OpenAPI document. */ - public const API_SPEC_VERSION = 'v2-2026-11-09T143926Z'; + public const API_SPEC_VERSION = 'v2-2026-11-10T140017Z'; private function __construct() { From 88bc14cc61db460e9a5ab305be5cfd87ddcf18f1 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 16:25:47 +0000 Subject: [PATCH 2/5] docs: write Apify Console in token notes Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_017ocuAJ6an2FrPuYqCvUoaA --- CHANGELOG.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 859c5d9..8b9fd9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Synced with Apify OpenAPI spec `v2-2026-11-10T140017Z`, which only changes descriptions. - Documented that `RunClient::charge()` is called from the Actor run with the `APIFY_TOKEN` of the run, and how to charge a multi-tenant Server Actor request. -- Documented that the Console shows an API token only once. +- Documented that Apify Console shows an API token only once. ## 0.14.0 diff --git a/README.md b/README.md index 0d726eb..543f2fe 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ echo 'Item count: ' . $items->getCount() . PHP_EOL; The client does not read `APIFY_TOKEN`. Pass it yourself, for example `new ApifyClient(getenv('APIFY_TOKEN'))`. You can create a token in [Apify Console → Settings → API & Integrations](https://console.apify.com/settings/integrations). -The Console shows a token only once, right after you create or rotate it, so store it somewhere safe. +Apify Console shows a token only once, right after you create or rotate it, so store it somewhere safe. ## Configuration From 9c6da5c53049a1039eac50e3a00ba8e7c86d01d8 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 16:54:03 +0000 Subject: [PATCH 3/5] chore: sync PHP client with Apify OpenAPI spec v2-2026-11-18T151559Z Document the reduced user data for proxy passwords and the nullable schedule uiState, and that metamorph needs the run's own token. Add a metamorph integration test and a unit test for the proxy user. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_017ocuAJ4DtkSFFSnhddsYup --- CHANGELOG.md | 4 +- docs/misc.md | 2 +- docs/models.md | 4 +- docs/runs.md | 2 +- src/Model/User.php | 2 + src/Resource/RunClient.php | 4 +- src/Resource/UserClient.php | 4 +- src/Version.php | 2 +- tests/Integration/ActorRunIntegrationTest.php | 56 +++++++++++++++++++ tests/Integration/IntegrationTestCase.php | 12 ++-- tests/Unit/SpecSyncTest.php | 19 +++++++ 11 files changed, 100 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b9fd9c..4da7f75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,11 @@ ## 0.14.1 -- Synced with Apify OpenAPI spec `v2-2026-11-10T140017Z`, which only changes descriptions. +- Synced with Apify OpenAPI spec `v2-2026-11-18T151559Z`: a user fetched with a proxy password has only `plan.availableProxyGroups`, `effectivePlatformFeatures` and `isPaying`, and a schedule's `uiState` can be `null`. Earlier spec changes since `v2-2026-11-09T143926Z` only change descriptions and tags. - Documented that `RunClient::charge()` is called from the Actor run with the `APIFY_TOKEN` of the run, and how to charge a multi-tenant Server Actor request. - Documented that Apify Console shows an API token only once. +- Documented that `RunClient::metamorph()` needs the run's own token, and that `UserClient::get()` returns reduced data for a proxy password. +- Added integration tests for `metamorph()` with the run's own token, and a unit test for a user fetched with a proxy password. ## 0.14.0 diff --git a/docs/misc.md b/docs/misc.md index 48cd880..5f822cf 100644 --- a/docs/misc.md +++ b/docs/misc.md @@ -22,7 +22,7 @@ foreach ($client->store()->iterate(new StoreListOptions(search: 'scraper'), 50) ## Users — `$client->me()` / `$client->user($id)` -- `get(): ?User`: for `me()`, the private account details are in `toArray()`. +- `get(): ?User`: for `me()`, the private account details are in `toArray()`. With a proxy password as the token, the API returns only `plan.availableProxyGroups`, `effectivePlatformFeatures` and `isPaying`, so `getId()` and `getUsername()` are `null`. - `monthlyUsage(?string $date = null): array`: the monthly usage of the cycle that contains `$date` (`YYYY-MM-DD`), by default the current month. - `limits(): array`, `updateLimits(mixed $newLimits): void`: the account limits. These three methods work for `me()` and for any user ID the token may access. diff --git a/docs/models.md b/docs/models.md index a5884f3..b2e41d7 100644 --- a/docs/models.md +++ b/docs/models.md @@ -96,6 +96,8 @@ kept as received. | `getCronExpression(): ?string` | The cron expression that triggers the schedule. | | `isEnabled(): ?bool` | Whether the schedule is enabled. | +The `uiState` field in `toArray()` is `null` once an API update changed the cron expression or timezone. + ### `Webhook` | Getter | Description | |---|---| @@ -116,7 +118,7 @@ kept as received. | `getId(): ?string` | The user ID. | | `getUsername(): ?string` | The username. | -Private account details (plan, email, etc.) returned by `me()->get()` are available via `toArray()`. +Private account details (plan, email, etc.) returned by `me()->get()` are available via `toArray()`. A proxy password gets only `plan.availableProxyGroups`, `effectivePlatformFeatures` and `isPaying`, so the ID and username are `null`. ### `ActorStoreListItem` Returned when listing/iterating the Apify Store. diff --git a/docs/runs.md b/docs/runs.md index 8da22c0..f767e34 100644 --- a/docs/runs.md +++ b/docs/runs.md @@ -23,7 +23,7 @@ An Actor's or task's runs are available at `$client->actor($id)->runs()` / `$cli - `update(mixed $newFields): ActorRun` - `delete(): void` - `abort(?bool $gracefully = null): ActorRun`: with `$gracefully` `true`, the run can finish its current request first. `false` and `null` (the default) abort at once. -- `metamorph(string $targetActorId, mixed $input = null, ?MetamorphOptions $options = null): ActorRun`: `$input` is as for `ActorClient::start()`. +- `metamorph(string $targetActorId, mixed $input = null, ?MetamorphOptions $options = null): ActorRun`: `$input` is as for `ActorClient::start()`. Only the run itself can metamorph: call it from the Actor run, with the token the run received in `APIFY_TOKEN`. Any other token is rejected. - `reboot(): ActorRun` - `resurrect(?RunResurrectOptions $options = null): ActorRun` - `charge(RunChargeOptions $options): void`: for pay-per-event Actors. Call it from the Actor run itself, with the token the run received in `APIFY_TOKEN`. For a multi-tenant Server Actor, set `requestId` to the request's `X-Actor-Request-ID` header value. diff --git a/src/Model/User.php b/src/Model/User.php index 682cd61..afa19a6 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -6,6 +6,8 @@ /** * A user account. The private details of {@code me}, such as email, plan, and proxy settings, are in {@see toArray()}. + * For a request authenticated with a proxy password, the API returns only the fields Apify Proxy reads + * ({@code plan.availableProxyGroups}, {@code effectivePlatformFeatures} and {@code isPaying}), without an ID or a username. */ final class User extends ApifyResource { diff --git a/src/Resource/RunClient.php b/src/Resource/RunClient.php index 098d5bf..4d0ddfc 100644 --- a/src/Resource/RunClient.php +++ b/src/Resource/RunClient.php @@ -107,7 +107,9 @@ public function abort(?bool $gracefully = null, int|float|string|null $timeoutSe } /** - * Transforms the run into a run of another Actor with a new input. + * Transforms the run into a run of another Actor with a new input. Only the run itself can metamorph: the client + * must use the run's own API token, which the run gets in the {@code APIFY_TOKEN} environment variable. With any + * other token, the API rejects the request. * * @param string $targetActorId the Actor to metamorph into * @param mixed $input the new input: a JSON-serializable value, a string sent as it is (set a diff --git a/src/Resource/UserClient.php b/src/Resource/UserClient.php index caf02f2..e8d7cde 100644 --- a/src/Resource/UserClient.php +++ b/src/Resource/UserClient.php @@ -24,7 +24,9 @@ public function __construct(private HttpClientCore $http, string $baseUrl, strin /** * Fetches the user: the private account details for {@code me}, the public profile for others. Returns - * {@code null} if the user does not exist. + * {@code null} if the user does not exist. With a proxy password as the token, the API returns only + * {@code plan.availableProxyGroups}, {@code effectivePlatformFeatures} and {@code isPaying}, so + * {@see User::getId()} and {@see User::getUsername()} are {@code null}; read the fields from {@see User::toArray()}. */ public function get(int|float|string|null $timeoutSecs = null): ?User { diff --git a/src/Version.php b/src/Version.php index 5644b6d..24c1aab 100644 --- a/src/Version.php +++ b/src/Version.php @@ -23,7 +23,7 @@ final class Version * The version of the Apify OpenAPI specification this client was generated and verified * against. Corresponds to the {@code info.version} field of the Apify OpenAPI document. */ - public const API_SPEC_VERSION = 'v2-2026-11-10T140017Z'; + public const API_SPEC_VERSION = 'v2-2026-11-18T151559Z'; private function __construct() { diff --git a/tests/Integration/ActorRunIntegrationTest.php b/tests/Integration/ActorRunIntegrationTest.php index a213e09..74a2ab4 100644 --- a/tests/Integration/ActorRunIntegrationTest.php +++ b/tests/Integration/ActorRunIntegrationTest.php @@ -6,6 +6,7 @@ use Apify\Client\ApifyClient; use Apify\Client\Internal\UrlNormalizer; +use Apify\Client\Options\ActorStartOptions; use Apify\Client\Options\DatasetListItemsOptions; use Apify\Client\Options\LastRunOptions; use Apify\Client\Options\ListOptions; @@ -136,6 +137,61 @@ public function testIterateDatasetItemsReadsItemsWhileTheRunIsStillRunning(): vo } } + public function testMetamorphWithTheRunsOwnTokenTransformsTheRunKeepingItsId(): void + { + $client = $this->requireClient(); + // An Actor that stores its run token under `TOKEN` in its key-value store, then waits for 240 seconds. + $script = <<<'JS' + const base = (process.env.APIFY_API_PUBLIC_BASE_URL || 'https://api.apify.com').replace(/\/$/, ''); + const url = `${base}/v2/key-value-stores/${process.env.APIFY_DEFAULT_KEY_VALUE_STORE_ID}/records/TOKEN?token=${process.env.APIFY_TOKEN}`; + (async () => { + const response = await fetch(url, { + method: 'PUT', + headers: { 'content-type': 'text/plain' }, + body: process.env.APIFY_TOKEN, + }); + if (!response.ok) throw new Error(`storing the token failed: ${response.status}`); + await new Promise((resolve) => setTimeout(resolve, 240000)); + })(); + JS; + $actorId = $this->createBuiltActor($client, 'metamorph', $script); + $runId = null; + try { + $run = $client->actor($actorId)->start(null, new ActorStartOptions(memoryMbytes: 256, timeoutSecs: 300)); + $runId = (string) $run->getId(); + $runClient = $client->run($runId); + + // The token is read well within the 240 seconds the Actor waits after storing it. + $runToken = null; + for ($attempt = 1; $attempt <= 60 && $runToken === null; $attempt++) { + $runToken = $client->keyValueStore((string) $run->getDefaultKeyValueStoreId())->getRecord('TOKEN')?->getValue(); + if ($runToken === null) { + self::assertContains($runClient->get()?->getStatus(), ['READY', 'RUNNING'], 'The run ended without storing its token.'); + sleep(2); + } + } + self::assertNotEmpty($runToken, 'The run did not store its token in time.'); + + $metamorphed = $this->requireClient(token: $runToken)->run($runId)->metamorph('apify/hello-world', ['message' => 'Hello from metamorph!']); + self::assertSame($runId, $metamorphed->getId()); + + // Hello-world replaces the waiting Actor, so the run finishes on its own. + $finished = $runClient->waitForFinish(300); + self::assertSame('SUCCEEDED', $finished->getStatus()); + self::assertIsArray($finished->get('metamorphs')); + self::assertCount(1, $finished->get('metamorphs')); + } finally { + if ($runId !== null) { + $runClient = $client->run($runId); + // Aborting a finished run returns it unchanged. + $runClient->abort(); + $runClient->waitForFinish(60); + $runClient->delete(); + } + $client->actor($actorId)->delete(); + } + } + /** * Creates an Actor with the script as {@code main.js}, waits for its build, and returns its ID. The caller deletes * the Actor. diff --git a/tests/Integration/IntegrationTestCase.php b/tests/Integration/IntegrationTestCase.php index 9859938..0218671 100644 --- a/tests/Integration/IntegrationTestCase.php +++ b/tests/Integration/IntegrationTestCase.php @@ -45,18 +45,22 @@ protected static function resolveBaseUrl(?string $apiUrl): string private const LISTING_MAX_ATTEMPTS = 30; private const LISTING_RETRY_DELAY_SECS = 3; - /** Returns a configured client, or skips the test if {@code APIFY_TOKEN} is unset. */ + /** + * Returns a configured client, or skips the test if {@code APIFY_TOKEN} is unset. The client uses + * {@code $token} instead of {@code APIFY_TOKEN} if given, for example the token of an Actor run. + */ protected function requireClient( string|HttpCompressorInterface|null $compression = null, ?HttpClientInterface $httpClient = null, + ?string $token = null, ): ApifyClient { - $token = getenv('APIFY_TOKEN'); - if ($token === false || $token === '') { + $envToken = getenv('APIFY_TOKEN'); + if ($envToken === false || $envToken === '') { self::markTestSkipped('skipping: APIFY_TOKEN is not set'); } $apiUrl = getenv('APIFY_API_URL'); return new ApifyClient( - token: $token, + token: $token ?? $envToken, baseUrl: self::resolveBaseUrl($apiUrl === false ? null : $apiUrl), httpClient: $httpClient, compression: $compression, diff --git a/tests/Unit/SpecSyncTest.php b/tests/Unit/SpecSyncTest.php index 92d5820..cb858fd 100644 --- a/tests/Unit/SpecSyncTest.php +++ b/tests/Unit/SpecSyncTest.php @@ -142,6 +142,25 @@ public function testScheduleWithANullUiStateIsReadAsIs(): void self::assertArrayHasKey('uiState', $schedule->toArray()); } + public function testUserFetchedWithAProxyPasswordHasNoIdOrUsername(): void + { + // The API returns only the fields Apify Proxy reads when the caller authenticates with a proxy password. + $proxyInfo = [ + 'plan' => ['availableProxyGroups' => ['GOOGLE_SERP']], + 'effectivePlatformFeatures' => [], + 'isPaying' => true, + ]; + $transport = (new MockTransport())->queueResponse(200, Json::encode(['data' => $proxyInfo])); + + $user = $this->client($transport)->me()->get(); + + self::assertNotNull($user); + self::assertNull($user->getId()); + self::assertNull($user->getUsername()); + self::assertSame(['GOOGLE_SERP'], $user->toArray()['plan']['availableProxyGroups']); + self::assertTrue($user->get('isPaying')); + } + public function testPendingStoredRequestWithANullHandledAtIsReadAsIs(): void { $transport = (new MockTransport())->queueResponse(200, Json::encode(['data' => [ From 8f75d2d3f903386e87588698f750477d1c0883fa Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 17:04:38 +0000 Subject: [PATCH 4/5] fix: address review of the spec v2-2026-11-18T151559Z sync Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_017ocuAJ4DtkSFFSnhddsYup --- CHANGELOG.md | 9 +-- docs/misc.md | 2 +- docs/models.md | 4 +- src/Model/User.php | 3 +- src/Resource/UserClient.php | 4 +- tests/Integration/ActorRunIntegrationTest.php | 78 ++++++++++++------- tests/Unit/SpecSyncTest.php | 4 +- 7 files changed, 62 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4da7f75..e219910 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,10 @@ ## 0.14.1 -- Synced with Apify OpenAPI spec `v2-2026-11-18T151559Z`: a user fetched with a proxy password has only `plan.availableProxyGroups`, `effectivePlatformFeatures` and `isPaying`, and a schedule's `uiState` can be `null`. Earlier spec changes since `v2-2026-11-09T143926Z` only change descriptions and tags. -- Documented that `RunClient::charge()` is called from the Actor run with the `APIFY_TOKEN` of the run, and how to charge a multi-tenant Server Actor request. -- Documented that Apify Console shows an API token only once. -- Documented that `RunClient::metamorph()` needs the run's own token, and that `UserClient::get()` returns reduced data for a proxy password. -- Added integration tests for `metamorph()` with the run's own token, and a unit test for a user fetched with a proxy password. +- Synced with Apify OpenAPI spec `v2-2026-11-18T151559Z`: `UserClient::get()` returns only `plan.availableProxyGroups`, `effectivePlatformFeatures` and `isPaying` for a proxy password. +- Documented that `RunClient::metamorph()` and `RunClient::charge()` need the run's own token. +- Documented that Apify Console shows an API token only once, and that a schedule's `uiState` can be `null`. +- Added a `metamorph()` integration test and a unit test for a user fetched with a proxy password. ## 0.14.0 diff --git a/docs/misc.md b/docs/misc.md index 5f822cf..e6fd46e 100644 --- a/docs/misc.md +++ b/docs/misc.md @@ -22,7 +22,7 @@ foreach ($client->store()->iterate(new StoreListOptions(search: 'scraper'), 50) ## Users — `$client->me()` / `$client->user($id)` -- `get(): ?User`: for `me()`, the private account details are in `toArray()`. With a proxy password as the token, the API returns only `plan.availableProxyGroups`, `effectivePlatformFeatures` and `isPaying`, so `getId()` and `getUsername()` are `null`. +- `get(): ?User`: the private account details, such as the plan and email, are in `toArray()` for `me()` and for a user ID fetched with a token of that account. A token with limited permissions never gets them, and `me()` omits `plan`, `email` and `profile` when called from an Actor run. With a proxy password as the token, the API returns only `plan.availableProxyGroups`, `effectivePlatformFeatures` and `isPaying`, so `getId()` and `getUsername()` are `null`. - `monthlyUsage(?string $date = null): array`: the monthly usage of the cycle that contains `$date` (`YYYY-MM-DD`), by default the current month. - `limits(): array`, `updateLimits(mixed $newLimits): void`: the account limits. These three methods work for `me()` and for any user ID the token may access. diff --git a/docs/models.md b/docs/models.md index b2e41d7..f4194be 100644 --- a/docs/models.md +++ b/docs/models.md @@ -96,7 +96,7 @@ kept as received. | `getCronExpression(): ?string` | The cron expression that triggers the schedule. | | `isEnabled(): ?bool` | Whether the schedule is enabled. | -The `uiState` field in `toArray()` is `null` once an API update changed the cron expression or timezone. +The `uiState` field in `toArray()` is `null` after an API update changes the cron expression or timezone. ### `Webhook` | Getter | Description | @@ -118,7 +118,7 @@ The `uiState` field in `toArray()` is `null` once an API update changed the cron | `getId(): ?string` | The user ID. | | `getUsername(): ?string` | The username. | -Private account details (plan, email, etc.) returned by `me()->get()` are available via `toArray()`. A proxy password gets only `plan.availableProxyGroups`, `effectivePlatformFeatures` and `isPaying`, so the ID and username are `null`. +Private account details (plan, email, etc.) are available via `toArray()` for `me()` and for a user ID fetched with a token of that account. A proxy password gets only `plan.availableProxyGroups`, `effectivePlatformFeatures` and `isPaying`, so the ID and username are `null`. ### `ActorStoreListItem` Returned when listing/iterating the Apify Store. diff --git a/src/Model/User.php b/src/Model/User.php index afa19a6..492724b 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -5,7 +5,8 @@ namespace Apify\Client\Model; /** - * A user account. The private details of {@code me}, such as email, plan, and proxy settings, are in {@see toArray()}. + * A user account. The private details, such as email, plan, and proxy settings, are in {@see toArray()}. The API returns + * them for {@code me} and for the user of the token, but not for other users or for a token with limited permissions. * For a request authenticated with a proxy password, the API returns only the fields Apify Proxy reads * ({@code plan.availableProxyGroups}, {@code effectivePlatformFeatures} and {@code isPaying}), without an ID or a username. */ diff --git a/src/Resource/UserClient.php b/src/Resource/UserClient.php index e8d7cde..f280b55 100644 --- a/src/Resource/UserClient.php +++ b/src/Resource/UserClient.php @@ -23,7 +23,9 @@ public function __construct(private HttpClientCore $http, string $baseUrl, strin } /** - * Fetches the user: the private account details for {@code me}, the public profile for others. Returns + * Fetches the user: the public profile, plus the private account details for {@code me} and for a user ID + * fetched with a token of that account. A token with limited permissions never gets the private details, and + * {@code me} omits {@code plan}, {@code email} and {@code profile} when called from an Actor run. Returns * {@code null} if the user does not exist. With a proxy password as the token, the API returns only * {@code plan.availableProxyGroups}, {@code effectivePlatformFeatures} and {@code isPaying}, so * {@see User::getId()} and {@see User::getUsername()} are {@code null}; read the fields from {@see User::toArray()}. diff --git a/tests/Integration/ActorRunIntegrationTest.php b/tests/Integration/ActorRunIntegrationTest.php index 74a2ab4..b6889db 100644 --- a/tests/Integration/ActorRunIntegrationTest.php +++ b/tests/Integration/ActorRunIntegrationTest.php @@ -16,6 +16,15 @@ final class ActorRunIntegrationTest extends IntegrationTestCase { + private const METAMORPH_RUN_MEMORY_MBYTES = 256; + private const METAMORPH_RUN_TIMEOUT_SECS = 300; + /** How long the metamorph Actor waits after storing its token. */ + private const METAMORPH_ACTOR_WAIT_SECS = 240; + private const METAMORPH_TOKEN_POLL_SECS = 2; + /** The polling budget (120 seconds) is shorter than the wait of the Actor, so the run is still alive when the token is read. */ + private const METAMORPH_TOKEN_MAX_ATTEMPTS = 60; + private const METAMORPH_FINISH_WAIT_SECS = 60; + public function testListRuns(): void { $client = $this->requireClient(); @@ -140,54 +149,63 @@ public function testIterateDatasetItemsReadsItemsWhileTheRunIsStillRunning(): vo public function testMetamorphWithTheRunsOwnTokenTransformsTheRunKeepingItsId(): void { $client = $this->requireClient(); - // An Actor that stores its run token under `TOKEN` in its key-value store, then waits for 240 seconds. - $script = <<<'JS' + // An Actor that stores its run token under `TOKEN` in its key-value store, then waits. + $waitSecs = self::METAMORPH_ACTOR_WAIT_SECS; + $script = << { const response = await fetch(url, { method: 'PUT', headers: { 'content-type': 'text/plain' }, body: process.env.APIFY_TOKEN, }); - if (!response.ok) throw new Error(`storing the token failed: ${response.status}`); - await new Promise((resolve) => setTimeout(resolve, 240000)); + if (!response.ok) throw new Error(`storing the token failed: \${response.status}`); + await new Promise((resolve) => setTimeout(resolve, {$waitSecs} * 1000)); })(); JS; $actorId = $this->createBuiltActor($client, 'metamorph', $script); - $runId = null; try { - $run = $client->actor($actorId)->start(null, new ActorStartOptions(memoryMbytes: 256, timeoutSecs: 300)); + $run = $client->actor($actorId)->start(null, new ActorStartOptions( + memoryMbytes: self::METAMORPH_RUN_MEMORY_MBYTES, + timeoutSecs: self::METAMORPH_RUN_TIMEOUT_SECS, + )); $runId = (string) $run->getId(); $runClient = $client->run($runId); - - // The token is read well within the 240 seconds the Actor waits after storing it. - $runToken = null; - for ($attempt = 1; $attempt <= 60 && $runToken === null; $attempt++) { - $runToken = $client->keyValueStore((string) $run->getDefaultKeyValueStoreId())->getRecord('TOKEN')?->getValue(); - if ($runToken === null) { - self::assertContains($runClient->get()?->getStatus(), ['READY', 'RUNNING'], 'The run ended without storing its token.'); - sleep(2); + try { + $tokenRecord = $client->keyValueStore((string) $run->getDefaultKeyValueStoreId()); + $runToken = null; + for ($attempt = 1; $attempt <= self::METAMORPH_TOKEN_MAX_ATTEMPTS && $runToken === null; $attempt++) { + $runToken = $tokenRecord->getRecord('TOKEN')?->getValue(); + if ($runToken === null) { + self::assertContains($runClient->get()?->getStatus(), ['READY', 'RUNNING'], 'The run ended without storing its token.'); + sleep(self::METAMORPH_TOKEN_POLL_SECS); + } } - } - self::assertNotEmpty($runToken, 'The run did not store its token in time.'); - - $metamorphed = $this->requireClient(token: $runToken)->run($runId)->metamorph('apify/hello-world', ['message' => 'Hello from metamorph!']); - self::assertSame($runId, $metamorphed->getId()); - - // Hello-world replaces the waiting Actor, so the run finishes on its own. - $finished = $runClient->waitForFinish(300); - self::assertSame('SUCCEEDED', $finished->getStatus()); - self::assertIsArray($finished->get('metamorphs')); - self::assertCount(1, $finished->get('metamorphs')); - } finally { - if ($runId !== null) { - $runClient = $client->run($runId); + self::assertNotEmpty($runToken, 'The run did not store its token in time.'); + // The token must not stay in storage. + $tokenRecord->deleteRecord('TOKEN'); + + $metamorphed = $this->requireClient(token: $runToken)->run($runId) + ->metamorph('apify/hello-world', ['message' => 'Hello from metamorph!']); + self::assertSame($runId, $metamorphed->getId()); + + // Hello-world replaces the waiting Actor, so the run finishes on its own. + $finished = $runClient->waitForFinish(self::METAMORPH_FINISH_WAIT_SECS); + self::assertSame('SUCCEEDED', $finished->getStatus()); + $helloWorldId = $client->actor('apify/hello-world')->get()?->getId(); + self::assertNotNull($helloWorldId); + $metamorphs = $finished->get('metamorphs'); + self::assertIsArray($metamorphs); + self::assertCount(1, $metamorphs); + self::assertSame($helloWorldId, $metamorphs[0]['actorId'] ?? null); + } finally { // Aborting a finished run returns it unchanged. $runClient->abort(); - $runClient->waitForFinish(60); + $runClient->waitForFinish(self::METAMORPH_FINISH_WAIT_SECS); $runClient->delete(); } + } finally { $client->actor($actorId)->delete(); } } diff --git a/tests/Unit/SpecSyncTest.php b/tests/Unit/SpecSyncTest.php index cb858fd..8f33308 100644 --- a/tests/Unit/SpecSyncTest.php +++ b/tests/Unit/SpecSyncTest.php @@ -146,7 +146,7 @@ public function testUserFetchedWithAProxyPasswordHasNoIdOrUsername(): void { // The API returns only the fields Apify Proxy reads when the caller authenticates with a proxy password. $proxyInfo = [ - 'plan' => ['availableProxyGroups' => ['GOOGLE_SERP']], + 'plan' => ['availableProxyGroups' => ['GOOGLE_SERP' => 200]], 'effectivePlatformFeatures' => [], 'isPaying' => true, ]; @@ -157,7 +157,7 @@ public function testUserFetchedWithAProxyPasswordHasNoIdOrUsername(): void self::assertNotNull($user); self::assertNull($user->getId()); self::assertNull($user->getUsername()); - self::assertSame(['GOOGLE_SERP'], $user->toArray()['plan']['availableProxyGroups']); + self::assertSame(200, $user->toArray()['plan']['availableProxyGroups']['GOOGLE_SERP']); self::assertTrue($user->get('isPaying')); } From 3f3fc63bb547031cc410451a63de81c8a5ade5b0 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 17:10:11 +0000 Subject: [PATCH 5/5] fix: name and explain the metamorph test constants Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_017ocuAJ4DtkSFFSnhddsYup --- tests/Integration/ActorRunIntegrationTest.php | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/Integration/ActorRunIntegrationTest.php b/tests/Integration/ActorRunIntegrationTest.php index b6889db..98f84bf 100644 --- a/tests/Integration/ActorRunIntegrationTest.php +++ b/tests/Integration/ActorRunIntegrationTest.php @@ -16,14 +16,20 @@ final class ActorRunIntegrationTest extends IntegrationTestCase { + /** Memory of the metamorph Actor run, enough for a script that makes one request. */ private const METAMORPH_RUN_MEMORY_MBYTES = 256; + /** Timeout of the metamorph run. It must exceed {@see METAMORPH_ACTOR_WAIT_SECS} plus the hello-world run. */ private const METAMORPH_RUN_TIMEOUT_SECS = 300; /** How long the metamorph Actor waits after storing its token. */ private const METAMORPH_ACTOR_WAIT_SECS = 240; + /** How long the test polls for the stored token. It must stay below {@see METAMORPH_ACTOR_WAIT_SECS}, or the run could end first. */ + private const METAMORPH_TOKEN_POLL_BUDGET_SECS = 120; + /** Seconds between two reads of the stored token. */ private const METAMORPH_TOKEN_POLL_SECS = 2; - /** The polling budget (120 seconds) is shorter than the wait of the Actor, so the run is still alive when the token is read. */ - private const METAMORPH_TOKEN_MAX_ATTEMPTS = 60; - private const METAMORPH_FINISH_WAIT_SECS = 60; + /** How long hello-world, which replaces the waiting Actor, gets to finish the run after the metamorph. */ + private const METAMORPH_HELLO_WORLD_WAIT_SECS = 300; + /** How long the cleanup waits for an aborted run to finish. */ + private const METAMORPH_ABORT_WAIT_SECS = 60; public function testListRuns(): void { @@ -173,10 +179,11 @@ public function testMetamorphWithTheRunsOwnTokenTransformsTheRunKeepingItsId(): $runId = (string) $run->getId(); $runClient = $client->run($runId); try { - $tokenRecord = $client->keyValueStore((string) $run->getDefaultKeyValueStoreId()); + $store = $client->keyValueStore((string) $run->getDefaultKeyValueStoreId()); $runToken = null; - for ($attempt = 1; $attempt <= self::METAMORPH_TOKEN_MAX_ATTEMPTS && $runToken === null; $attempt++) { - $runToken = $tokenRecord->getRecord('TOKEN')?->getValue(); + $maxAttempts = intdiv(self::METAMORPH_TOKEN_POLL_BUDGET_SECS, self::METAMORPH_TOKEN_POLL_SECS); + for ($attempt = 1; $attempt <= $maxAttempts && $runToken === null; $attempt++) { + $runToken = $store->getRecord('TOKEN')?->getValue(); if ($runToken === null) { self::assertContains($runClient->get()?->getStatus(), ['READY', 'RUNNING'], 'The run ended without storing its token.'); sleep(self::METAMORPH_TOKEN_POLL_SECS); @@ -184,14 +191,14 @@ public function testMetamorphWithTheRunsOwnTokenTransformsTheRunKeepingItsId(): } self::assertNotEmpty($runToken, 'The run did not store its token in time.'); // The token must not stay in storage. - $tokenRecord->deleteRecord('TOKEN'); + $store->deleteRecord('TOKEN'); $metamorphed = $this->requireClient(token: $runToken)->run($runId) ->metamorph('apify/hello-world', ['message' => 'Hello from metamorph!']); self::assertSame($runId, $metamorphed->getId()); // Hello-world replaces the waiting Actor, so the run finishes on its own. - $finished = $runClient->waitForFinish(self::METAMORPH_FINISH_WAIT_SECS); + $finished = $runClient->waitForFinish(self::METAMORPH_HELLO_WORLD_WAIT_SECS); self::assertSame('SUCCEEDED', $finished->getStatus()); $helloWorldId = $client->actor('apify/hello-world')->get()?->getId(); self::assertNotNull($helloWorldId); @@ -202,7 +209,7 @@ public function testMetamorphWithTheRunsOwnTokenTransformsTheRunKeepingItsId(): } finally { // Aborting a finished run returns it unchanged. $runClient->abort(); - $runClient->waitForFinish(self::METAMORPH_FINISH_WAIT_SECS); + $runClient->waitForFinish(self::METAMORPH_ABORT_WAIT_SECS); $runClient->delete(); } } finally {